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.

Getting all Lead (entry) data submitted within gform_validation

  1. I'm trying to pull in all field data from the validation action I'm running. See below for my code, I don't think it's entirely right - any input? Also it doesn't pull in uploaded file information either.

    if (!isset($validation['form']) && isset($validation['fields']))
        $fields = $validation['fields'];
    else
        $fields = $validation['form']['fields'];
    $entry = array();
    foreach ($fields as $field) {
        $value = RGFormsModel::get_field_value($field);
        if (is_array($value))
            $value = implode('|', $value);
        $entry[$field['id']] = $value;
    }
    Posted 12 years ago on Wednesday December 14, 2011 | Permalink
  2. $validation is coming from the first parameter I'm getting from within the function that's used in this filter:

    add_filter('gform_validation', 'my_gf_validation', 1, 1);

    Posted 12 years ago on Wednesday December 14, 2011 | Permalink
  3. Hi, Scott,

    Have you reviewed the documentation on this hook, it is pretty extensive and may help you out - http://www.gravityhelp.com/documentation/page/Using_the_Gravity_Forms_%22gform_validation%22_Hook

    There is also the less detailed info of the hook at http://www.gravityhelp.com/documentation/page/Gform_validation .

    If you are only trying to validate a single field, you can use the newer hook gform_field_validation - http://www.gravityhelp.com/documentation/page/Gform_field_validation .

    Take a look at those articles and let us know if you still need some guidance.

    Posted 12 years ago on Wednesday December 14, 2011 | Permalink
  4. It seems like this doesn't cover file uploads, at this point for some reason, I'm getting no value for the file upload field. I'm going to try debugging more, but it's just odd that I can't get it from the fields array like all the other values that I'm able to get.

    Posted 12 years ago on Thursday December 15, 2011 | Permalink
  5. Tried a few different ways, no luck, everything seems to be a private method that I'm attempting to use. Hopefully someone can shed more light on the issue.

    Posted 12 years ago on Thursday December 15, 2011 | Permalink
  6. Hi, Scott,

    I have posted an example of using the validation hook to pull out information from the submitted form which includes a file upload. Take a look at the sample here: http://pastie.org/3022992 .

    The data submitted by the user is available in the $_POST object and the uploaded file information (size, temp name, name) is available in the $_FILES object.

    Take a look and let me know if you have questions, but I think this will get you where you want to be.

    Posted 12 years ago on Thursday December 15, 2011 | Permalink
  7. Ouch, can't this data be readied before it comes to the hook? Seems like hitting $_POST and $_FILES in your own validation function is really a bad idea. I'll use it for now, just voicing my very strong opinion on the lacking functionality for us who choose to hook (lol, don't be dirty!)

    Posted 12 years ago on Thursday December 15, 2011 | Permalink
  8. Readying the data for actual storage in the database is fairly involved and for some fields requires actually changing the raw submitted value. Allowing you to modify these values in the $_POST and $_FILES (before Gravity Forms alters them) gives you complete control of the raw values before GF takes over to finish the job. Power to the hookers! ;)

    Posted 12 years ago on Thursday December 15, 2011 | Permalink
  9. I see.. then at least build the function that does the readying of the $_POST/$_FILES data for us, so that we can use it in the validation, modify the $_POST etc ourselves if we absolutely need to. Then you could also use that same function in core during the processing (after validation) to re-setup the same code. At least we'd be able to use that function, and if we don't, the function never runs at validation and just runs when GF does processing.

    Make sense? Yay hookers!

    Posted 12 years ago on Thursday December 15, 2011 | Permalink
  10. Also, one of my use-cases for the file data is actually to take the file (after it's been processed by WP upload handler) and upload it to another service (I give it a URL), or if it's an image then resize it locally using the WP image resizing functions. Actually, for my purposes, all of my forms delete entries upon success, they're all mapped to Pods using the new GF >> Pods mapping code I've built.

    Posted 12 years ago on Thursday December 15, 2011 | Permalink
  11. Also Dana, does the code you posted above cover fields that have multiple fields in them, like the first/last name combo field, or address field, checkboxes, etc?

    Posted 12 years ago on Friday December 16, 2011 | Permalink
  12. No, the code I posted does not cover the multi-input fields. Take a look at the Advanced Fields section and the information about "inputs" at http://www.gravityhelp.com/documentation/page/Field_Object .

    What you can do, is while looping through the fields, you can check to see if there are inputs and get the values for the individual pieces. In the example below if there are inputs, I loop through the inputs, get the id of the individual field and get the value from $_POST (using rgpost to handle when a field isn't set, like a checkbox not checked). The id in the inputs collection will be something like 3.3, but in $_POST it will be input_3_3.

    //see if field has inputs
    if(rgar($field, "inputs"))
    {
    	//get individual field info
    	foreach($field["inputs"] as $input){
    		//get name of individual field, replace period with underscore when pulling from post
    		$input_name = "input_" . str_replace(".","_",$input["id"]);
    		$value = rgpost($input_name);
    		//do whatever validation on the value you want
    	}
    }
    Posted 12 years ago on Tuesday December 20, 2011 | Permalink
  13. Any chance all this information can be fleshed out into a single function that's included in the next version? I can't think of anyone, who does validation, who would think this useless - it's exactly what they'd look for. It sucks having everyone code up their own home brewed version of this, it wouldn't suck having a function in GF to utilize that's standardized and gives back everything as you'd expect it.

    Posted 12 years ago on Wednesday December 21, 2011 | Permalink
  14. I should also mention that this is definitely needed for Pods integration, though I can put in a work around - it'll just be hacky and all $_POSTy, that's asking for trouble and the code should rely on GF itself to present the data so that as anything changes in the future, I'm still getting back what I need as it expects.

    Posted 12 years ago on Wednesday December 21, 2011 | Permalink
  15. Talked to Alex, I know you guys are busy, just threw that out there so it would be somewhere on a list some place, I know issues like this is just part of GF evolving. I'll send it along to your team once I have the code finished up and working, just been rough since documentation was lax on everything I needed to be pulling in from the form submission during validation

    Posted 12 years ago on Wednesday December 21, 2011 | Permalink

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