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 values of form fields

  1. sascha
    Member

    Hi there,

    somehow I am struggling to get the value of the form fields with this code below. I just try to dump $entry, but nothing shows. It just returns NULL.

    add_action('gform_after_submission_11', 'update_individual_fields_11');
    
    function update_individual_fields_11($entry) {
        $form = RGFormsModel::get_form_meta('11');
    	global $entry;
    	$post_field = $form[fields][0]["postCustomFieldName"];
    	echo 'form[fields]';
    	var_dump ($form[fields]);
    	//global $form;
    	echo '</br>';
    	echo '</br>';
    	$id = 218; //need to get the current post value there!
    	echo '$form';
    	var_dump($form); // form object
    	echo '</br>';
    	echo '</br>';
    	echo '$entry: ';
    	// ----------------------------------------------------------------
    	var_dump($entry); // entry object -------is not availabe?????????
    	// how do I pull the submitted data from form?
    	// ---------------------------------------------------------
    	echo '</br>';
    	echo '</br>';
    	echo 'Post custom field name: ' . $post_field . '</br>';
    		// Create entry in post meta
    		update_post_meta($id, $post_field, 'value from form here', true);
    		echo '</br>';
    		echo '</br>';
    		var_dump($entry);
    }

    I am sure I am missing something very basic... Just cannot find a way. Any ideas? Thanks!

    And (basics again) when do I use just:
    global $form and when do I use that:
    $form = RGFormsModel::get_form_meta('11');

    Is there some documentation on RGFormsModel:: stuff. I am not a coder so struggling with those syntax bits.

    In the above example global $form did not seem to work...

    Posted 12 years ago on Monday January 16, 2012 | Permalink
  2. Hi Sascha,

    First off, this documentation will demonstrate how you can pass the $form object as well as the $entry object to your function:

    http://www.gravityhelp.com/documentation/page/Gform_after_submission

    Secondly, try dumping $entry at the very top of your function and see what happens. You also do not need to add the "global $entry" bit. Let me know. :)

    Posted 12 years ago on Monday January 16, 2012 | Permalink
  3. sascha
    Member

    Hey David,

    that sorted it! Thanks!

    add_action('gform_after_submission_11', 'update_individual_fields_11', 10, 2);
    
    function update_individual_fields_11($entry, $form) {
    	var_dump($entry);
    	echo '</br>';
    	echo '</br>';
        $form = RGFormsModel::get_form_meta('11');

    BTW: can I pass any values/variables to the function in the brackets? And do I still need the RGFormsModel stuff or is $form just accessible, when I put it in the brackets of the function?

    Posted 12 years ago on Monday January 16, 2012 | Permalink
  4. Hi Sascha,

    You can only pass the variables that are available to that that hook. They will all be documented in the documentation for that hook. In this case, the only variables available are the $entry object and the $form object.

    Posted 12 years ago on Monday January 16, 2012 | Permalink