Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change Element's Name Attribute in Gravity Forms

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?

like image 732
solepixel Avatar asked Mar 19 '12 20:03

solepixel


1 Answers

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

like image 98
Brandon Burke Avatar answered Oct 04 '22 06:10

Brandon Burke