PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

How-to return product Quantity for validation

  1. How do we return product quantity in gform_hooks ?

    Posted 6 years ago on Thursday November 22, 2012 | Permalink
  2. David Peralty
    Administrator

    Can you give me more information on what you are trying to do? I don't understand.

    Posted 6 years ago on Thursday November 22, 2012 | Permalink
  3. I'm triying to return the value for the product qty.
    I need to validate qty field. It should be trivial no?

    Check this out: http://projets.collectiv.ca/northsec-2013/

    Something like this maybe ...

    http://www.gravityhelp.com/documentation/index.php?title=Gravity_Forms_Pricing:_Adding_Tax&oldid=1514

    But in gform_field_validation hook.

    Posted 6 years ago on Thursday November 22, 2012 | Permalink
  4. David Peralty
    Administrator

    Have you tried the following?
    http://www.gravityhelp.com/documentation/page/Gform_field_validation

    Posted 6 years ago on Thursday November 22, 2012 | Permalink
  5. I would like to test if my list field rows == product quantity in the second step.
    Since the quantity field is in the step 1, it is not validated on step 2

    The quantity would be use to populate the field list with the required rows.

    Posted 6 years ago on Thursday November 22, 2012 | Permalink
  6. I would really appreciate some help on this one.

    All I need to do is to populate a list field with a qty collected in the first step.
    Here is the code:

    // Populate list with selected quantity
    add_filter("gform_pre_render_1", "pre_populate_row_list");
    function pre_populate_row_list($form){
    
    	$field_id = 15; // Member list
    	$product_qty = rgpost('input_30');
    	$list = rgpost('input_15');
    
    	$current_page = GFFormDisplay::get_current_page($form["id"]);
    
    	//if($current_page == 2){
    		foreach($form['fields'] as &$field){
    			if($field['id'] != $field_id)
    				continue;	
    
    			// Dynamic Population doesn't work :\
    			$array = array_fill(0, $product_qty ,'');
    			$field['choices'] = array_fill(0, 2, $array);
    			//$field['label'] = implode(',',$field['choices']);
    		}
    	//}
    	return $form;
    }
     

    Posted 6 years ago on Friday November 23, 2012 | Permalink
  7. David Peralty
    Administrator

    So I don't think you can use pre_render to take something from one section of a form and populate another. Because when pre_render has run, no one has typed anything in yet.

    Have you looked at this:
    http://www.gravityhelp.com/documentation/page/Gform_post_paging

    Posted 6 years ago on Friday November 23, 2012 | Permalink
  8. Thanks. Thats how I did it finaly.

    add_filter("gform_field_validation_1_15", "validate_list_field", 10, 4);
    function validate_list_field($result, $value, $form, $field){
    
        $product_qty = rgpost('input_33');
    
        // Test if equal quantity
        if( count($current_emails) != $product_qty ){
            $result["is_valid"] = false;
            $result["message"] .= sprintf(__('<br/>Vous devez inscrire (%d) personnes dans votre équipe.','nsec'), $product_qty);
        }
    
        // always return result
        return $result;
    }
    Posted 6 years ago on Friday November 30, 2012 | Permalink
  9. Thank you for sharing your code.

    Posted 6 years ago on Saturday December 1, 2012 | Permalink

This topic has been resolved and has been closed to new replies.