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.

Add Additional Hidden Field Attributes

  1. rnewman
    Member

    Is there a way to add id, name and title attributes to hidden fields? It seems the only option available is the value attribute.

    Posted 12 years ago on Thursday December 6, 2012 | Permalink
  2. Richard Vav
    Administrator

    The hidden field already has an id and name which can be found on the title bar of the fields properties panel when hovered over or opened, as an example the id is formatted as 'input_1_6' and the name is 'input_6', the 1 represents the form id which can be found by hovering over the form settings panel at the top of form editor. You could add the title attribute by using jquery and something like this

    $('#input_1_6').attr('title', 'i am a hidden field');

    Posted 12 years ago on Thursday December 6, 2012 | Permalink
  3. Do you have a complete code example for me? Something to copy/paste?

    Posted 11 years ago on Thursday January 3, 2013 | Permalink
  4. @leanderb, can you please post a link to the page on your site where the form is embedded? Also, please ask what you would like to do with your form exactly. Thank you.

    Posted 11 years ago on Thursday January 3, 2013 | Permalink
  5. Hey Chris,

    sure thing, sorry:

    I need the form to act within a payment process and pass along some custom, hidden variables. When I read the output of the shortcode-embedded Gravity Form, there is a correct (default) value presented but the name is overwritten with ing something like "input_5". That is not sufficient for my needs. See code:

    <li id="field_1_5" class="gfield gform_hidden">
    <input id="input_1_5" class="gform_hidden" type="hidden" value="rdstnz" name="input_5">
    </li>
    <li id="field_1_6" class="gfield gform_hidden">
    <input id="input_1_6" class="gform_hidden" type="hidden" value="Mitgliedsaccount-Er-distanziert-sich" name="input_6">
    </li>
    <li id="field_1_7" class="gfield gform_hidden">
    <input id="input_1_7" class="gform_hidden" type="hidden" value="100" name="input_7">
    </li>

    Live: http://www.er-distanziert-sich.info/bestellen (temporary, I am editing this page currently)

    I am unaware of how to write my own JQuery-Code and have not succeeded in coating the above $('#input_1_6').attr('title', 'i am a hidden field'); properly. I'd either like to use a fully written and working code-sample or maybe a hint at another option.

    Thanks so much!

    Posted 11 years ago on Thursday January 3, 2013 | Permalink
  6. leanderb, your issue is completely unrelated to the issue which was originally asked here.

    You can't change the id of a hidden field without breaking Gravity Forms. How are you sending your data to the payment processor? Can you share you code here?

    So far, nothing you want to do is related to jQuery that I can see.

    Posted 11 years ago on Sunday January 6, 2013 | Permalink
  7. Hey Chris,

    sorry if things got mixed up, that wasn't my intention. But since richardvav is also talking about changing the name of a hidden form field from default to another value, I guessed to be right with my question.

    If there is no way to add custom names to hidden form fields (original question by rnewman) how can I manage to work around that? I tried the approach presented by richardvav, but couldn't follow along...

    Posted 11 years ago on Tuesday January 8, 2013 | Permalink
  8. rnewman was looking to add id, name and title attributes to the fields, which can be accomplished as richardvav explained, using jQuery. That is adding additional attributes to existing fields. richardvav technically did not address adding the name, since the name is already present and is how the jQuery would know to target that element.

    It sounds to me like you actually want to change the name of the field from input_7, correct? If you actually need the names of the input changed, you won't be able to do that and not break Gravity Forms. Gravity Forms requires that those input ID be in the format as it was output.

    Can you share more information about what you actually need to send, and to where? Maybe there is a way using the gform_after_submission hook. Without more details from you, it's difficult to help you achieve your goal.

    Posted 11 years ago on Wednesday January 9, 2013 | Permalink
  9. My bad. Yeah, I want to change the name of the field from say 'input_5' to 'project' because this is the variable needed when passing on the info to my payment provider. There they grab those additional parameters and pass them back to my site after payment has been made out.

    It is tricky, because I have to have those parameters entered BEFORE payment as they are expected to be already set for the membership-plugin registration-process afterwards.

    Regarding the gform_after_submission hook: Would the code go into my theme's functions.php? Sorry, the documentation skipped that part for one is expected to have that covered I guess.

    Posted 11 years ago on Thursday January 10, 2013 | Permalink
  10. Yes, the code will go in your theme's functions.php.

    Posted 11 years ago on Thursday January 10, 2013 | Permalink