Something like this may be posted elsewhere, but as I haven't found it, figured I'd post in case it helps someone else.
I needed to use custom values for some drop down menus on a form I'm doing for a client. This is my first time using Gravity Forms and I found here in the forums that you have to do a bit of coding to accomplish this -- the built in functionality is to make the value and the label of a field be the same. So if you need option 1 value='1" and the displayed value = First Option, you've go to do some work.
The solution posted here in the forums requires you to get the field ID of the field you want to use custom values for by looking at the source code of the form. No big deal if you're only modifying one or two fields, but I have the drop down repeated potentially up to 10 times on the form.
The work around I came up with is to add a custom css class to the form field. In this case, I have a dropdown menu that I gave a css class of "customvalues". I then use that css class to access the fields and use the custom values:
add_filter('gform_pre_render_1', 'fieldvals');
function fieldvals($form){
items = array();
$items[] = array('text' => "-Displayed Value 1", "value" => '10');
$items[] = array('text' => "Displayed Value 2", "value" => '20');
$items[] = array('text' => "Displayed Value 3", "value" => '30');
foreach($form["fields"] as &$field)
if($field["cssClass"] == "customvalues"){
$field["type"] = "select";
$field["choices"] = $items;
}
return $form;
}
If you want to do any dynamic updating on the form, you can then access those dropdowns using jquery and the same css class, like so :
jQuery(document).ready(function($jq) {
$jq(".customvalues select").change(function(){
$jq(".customvalues option:selected").each(function(i){
alert($jq(this).val());
});
});
});
I'm using it to dynamically calculate totals based on membership options selected on a member sign up form and display the running total. The example above just alerts the value of the selected options.