Change Element's Name Attribute in Gravity Forms
Asked Answered
C

2

6

Is it possible via some sort of Hook or Filter to change the "name" attribute on a form element in Gravity Forms? It allows you to select "Allow field to be populated dynamically" and then set a "Parameter Name", however the parameter name doesn't match up with the element's name attribute. My element's names are like input_6_1 or something.

I'm trying to avoid using jQuery to accomplish this, but I suppose I will resort to it as a last resort. Any ideas?

Catarina answered 19/3, 2012 at 20:6 Comment(1)
Im in the same boat as you and as far as im aware you can't. Their documentation is poor...var!=object and array!=property but they don't know this ;)Iconoscope
F
1

It isn't the most beutiful code, and I'm not sure if there is a gravity forms approved way (it wasn't apparent to me), but something like this should work for you.

<script type="text/javascript">
    jQuery(document).ready(function() {     
        jQuery('#input_1').attr('name','YOURCUSTOMNAMEVALU');
    });
</script>

Also, for WordPress you should probably wrap it in a scope to contain this to the page that contains your form.

Something like

<?php
if(is_page('forms-page') && !is_admin()) {
?>
//Javascript Here
<?php } ?>

For style points you can use enqueue_script to include it from your functions.php

Farad answered 10/8, 2012 at 21:37 Comment(1)
Yeah this is pretty much what I ended up doing. In the end I realized that a gravity form probably wasn't even necessary, but just a simple dynamically built form would've worked. Oh well. Thanks!Catarina
P
1

Set the parameter name to something like 'customparam'.

Then dynamically populate it using a filter.

add_filter('gform_field_value_customparam', 'populate_customparam');

function populate_customparam($value){
    return 'Hello';
}

This will dynamically insert 'Hello' into every gravity form field with parameter named 'customparam'

Predicable answered 27/8, 2012 at 12:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.