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.

Create "Static" Field Names?

  1. Edh
    Member

    Hi,

    I am writing a plugin to post-process form data using a gform_after_submission hook.

    I am after several specific fields that will appear across multiple forms (but not always in the same placement)

    Is there any way (during form creation) to create a field name/ID to be a static value that the plugin can always find, so that it does not need to be updated every-time a new form is added (or changed)

    As an Example, the phone number of this form is the first field, but on other forms it it the 3rd field & 11th field. I'd like to use the same line of code to get all of them regardless of the field position.
    $phoneNum = ($_POST['input_1']);

    hope this makes sense.

    Thanks!
    -Ed

    Posted 13 years ago on Wednesday October 19, 2011 | Permalink
  2. Edh
    Member

    Is this possible?

    Thanks,
    -Ed

    Posted 13 years ago on Saturday October 22, 2011 | Permalink
  3. The field names are dynamically created for each form. I don't think it would be possible to assign static names. So, we need another approach.

    If you want to apply some processing to all forms, you can assign a custom CSS class in the form builder. Then, you can process any field with that specific CSS class. Here are a couple of snippets you can incorporate into your function.

    This will look through your form for any field with the custom CSS class my_class and apply your processing to that field:

    [php]
    if(strpos($field['cssClass'], 'my_class') === true) {
    // process this field
    }

    and

    [php]
    if($field['type'] = 'select') { // or whatever TYPE of field you want to process
    // process this field
    }

    You can combine them as well, like this:

    [php]
    if($field['type'] = 'select' && (strpos($field['cssClass'], 'my_class') === true)) {
    // process this field
    }

    Here's an example of looping through all the fields in a form, to see how it works:

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

    You would be using the same process with gform_after_submission rather than gform_pre_render.

    Also, gform_after_submission is available in 1.6 and later, so be sure you're using the latest release candidate.

    Posted 13 years ago on Saturday October 22, 2011 | Permalink
  4. Edh
    Member

    Thanks, Chris.

    I had thought about using the CSS as a workaround, but then they (might) complicate the UI.

    Would it be possible in a future update to allow an advanced option to set either the field name or ID? (or does GF really use both for processing)?

    Thanks again,
    -Ed

    Posted 13 years ago on Saturday October 22, 2011 | Permalink
  5. I will bring this post to Carl's attention to consider your suggestion. Thank you.

    Posted 13 years ago on Saturday October 22, 2011 | Permalink