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.

Function call and $field_values

  1. Fredrik-s


    I'm trying to use the function call -way to import a form into a Wordpress theme page. This works great with:

    		$field_values = array(

    As you also can se I'm trying to add field values through the $field_values command. And here it's where I bump into problem.

    Nothing want show up in the hidden fields which I added when creating the form. The hidden fields are set to the following:

    "Allow field to be populated dynamically" is checked
    "Parameter Name:" is set to the six seen above in the code
    Label name is also set to the six seen above in the code

    The parameters $namn, $url, $vanlig_url, $typ, $registrering, $kategori are all checked and the output the information I want in my hidden fields.

    The source code which is being output looks like this:

    <li id='field_3_3' class='gfield     gform_hidden' >
    <input name='input_3' id='input_3_3' type='hidden' class='gform_hidden' value='' />
    <li id='field_3_4' class='gfield     gform_hidden' >
    <input name='input_4' id='input_3_4' type='hidden' class='gform_hidden' value='' />
    <li id='field_3_5' class='gfield     gform_hidden' >
    <input name='input_5' id='input_3_5' type='hidden' class='gform_hidden' value='' />
    <li id='field_3_6' class='gfield     gform_hidden' >
    <input name='input_6' id='input_3_6' type='hidden' class='gform_hidden' value='' />
    <li id='field_3_7' class='gfield     gform_hidden' >
    <input name='input_7' id='input_3_7' type='hidden' class='gform_hidden' value='' />
    <li id='field_3_8' class='gfield     gform_hidden' >
    <input name='input_8' id='input_3_8' type='hidden' class='gform_hidden' value='' />

    What am I doing wrong? And how to solve it?

    Posted 11 years ago on Wednesday April 6, 2011 | Permalink
  2. Hi there, the issue is that the $field_values parameter should be defined before the $ajax parameter. Let me know if that does the trick.

    Posted 11 years ago on Wednesday April 6, 2011 | Permalink
  3. Fredrik-s

    That worked fine.

    I have a following question due.

    The above code is suppose to be in a form where the visitors can write a review (post body of post) if there is none written (post body). I have a connection to a custom post type (through the available fix Gravity Forms + Custom Post Types).

    Title: Toyota Supra
    Post body: Not-written-yet
    Field values: Type=Car, Color=Red, Speed=Fast

    As you can se above example should be able to be updated through a form. I do a check with a if-expression to se if the post body is empty (this works fine showing the form). In above example this is the case.

    So I show a form (Gravity form) and the visitor could write a review into the post body. I take all the other values and send with through hidden fields.

    But when I sign this form up it will not update the old one, instead showing up like a copy beside the other.

    How can I do to update the existing post with just the post body that the visitor have written?

    Posted 11 years ago on Wednesday April 6, 2011 | Permalink
  4. Conceptually, all you'd need to do is conditionally use the gform_disable_post_creation hook to disable post creation when the user is editing through the Gravity Form. This would be a condition that would need to be created and checked in your own custom code.

    If the user is in "edit" mode, you can then use a combination of the wp_update_post function (to update the post title, post body, etc) and update_post_meta function (to update the post meta).

    Posted 11 years ago on Wednesday April 6, 2011 | Permalink
  5. sascha

    Hi there,
    I do not understand the $field_values in the the above example. I could not find anything in the documentation yet either. Can the $field_values also be used when calling a form by shortcode? Would I use $field_values to pre-populate fields?

    How would I set a form up, so that it does not create a post, but uses the wp_update_post function instead?

    Posted 10 years ago on Wednesday January 18, 2012 | Permalink