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.

Creating hidden fields with static values ...

  1. Hiya,

    We're looking to create hidden fields in forms with static values ... just for internal tracking more than anything else, and to make some coding easier to do.

    Now, I see in js.php, in the SetDefaultValues() JS function, switch() statement, the 'hidden' field goes something like this:

    case "hidden" :
                field.inputs = null;
                if(!field.label)
                    field.label = "<?php _e("Hidden Field", "gravityforms"); ?>";
                break;

    I'm making an additional entry in the switch JS there, and trying to find a way to set the value of the hidden field while creating it. field.value and field.content do not work for this purpose, is there another attribute that would? Alternatively, is there another method that I could call this via javascript? I'm outputting my JS following the contents of js.php via the 'gform_editor_js' action hook.

    Posted 11 years ago on Tuesday March 8, 2011 | Permalink
  2. Here is a post that discusses how to populate a field (hidden or otherwise) dynamically using PHP:

    http://www.gravityhelp.com/forums/topic/using-custom-fields-to-populate-hidden-fields#post-17616

    Posted 11 years ago on Tuesday March 8, 2011 | Permalink
  3. Well ... kinda maybe, I guess. Best as I can figure with that method, I'd have to store the value in the meta of the post that contains the form, then do something like ...

    add_filter("gform_field_value_myfield", "populate_myfield");
    function populate_myfield($value){
    return get_post_meta($GLOBALS['post']->ID, 'myfield', true);
    }

    like you said, but ... there's no way to pre-populate them as a static value from the form editing page? Because with that method, it's case will depend on where the form is placed. We want it to be static on a form-by-form basis, regardless of where that form is placed.

    Make sense?

    Posted 11 years ago on Tuesday March 8, 2011 | Permalink
  4. From the editor itself? I don't think there is a hook for the default value in the form editor.

    The problem is you need some identifier to know which field to target and pre-populate.

    In Gravity Forms v1.5 there are some new hooks that will make this possible taking another route, but the field would still have to be added to the form. You could use hooks/filters to create your own custom field type that incorporates your default value, etc. But the field would still have to be added to the form in the form editor, it wouldn't automatically be added.

    Posted 11 years ago on Wednesday March 9, 2011 | Permalink
  5. Yeah, that's the problem. I've added some filters/hooks to 1.5 to let me add new custom field types and the like (and started another thread asking for some to be rolled into to the source) ... but I can't seem to sort out exactly how to finagle this.

    Is there some documentation explaining exactly what properties the field object (in JS, that gets sacked back and forth from php) can have, how to set them, and what they mean?

    Also -- one thing to tidy up the JS a bit -- you can do the following:

    jQuery(document).ready(function($){
        $('div#blah').whatever();
    });

    -- as a shortcut to use $ in noconflict mode ... just pass $ to the function. I saw in the JS you were using the long-hand version for all of it, and it can get a bit messy to parse through.

    Cheers!

    Posted 11 years ago on Thursday March 10, 2011 | Permalink
  6. There is no documentation for the field object itself. The only documentation we provide is for exposed API hooks/filters. We don't document every piece of core code for users because they are supposed to interact with the plugin via customizations using API hooks/filters designed to be used by end users.

    There will be documentation for all the available hooks/filters in the new web site that will launch with the final release of 1.5 which will be launching very soon.

    Posted 11 years ago on Thursday March 10, 2011 | Permalink
  7. Rightio. One potential discrepancy I've found is that it seems the HTML elements that get shoved in a form seem to get set
    field.inputType = 'html';
    whereas all other field types get set
    field.type = "select";
    or the like. Is this syntax intended to merge at some point in the future? I'd hate to code to one set of data, only to have the back-end plugin of GravityForms pull the carpet out from underneath me after an upgrade!

    Posted 11 years ago on Thursday March 10, 2011 | Permalink
  8. Okay, just made progress. Started thinking about the properties as a cohesive whole, so a property set in javascript is the same as a property set in php, as they translate directly. Now I've got a whole lot more I can tweak with the custom fields. Sweetness! Thanks again!

    Posted 11 years ago on Friday March 11, 2011 | Permalink