Skip to content

Instantly share code, notes, and snippets.

@jorgepedret
Created June 9, 2011 13:07
Show Gist options
  • Save jorgepedret/1016695 to your computer and use it in GitHub Desktop.
Save jorgepedret/1016695 to your computer and use it in GitHub Desktop.
Gravity Forms Custom Fields
<?php
add_action("gform_field_input", "ih_gform_field_input", 10, 5);
function ih_gform_field_input($input, $field, $value, $lead_id, $form_id){
//wp_debug($field);
if($field["type"] == "vehicleyear"){
//wp_debug($field['choices']);
//$input = 'Aha!';
}
return $input;
}
add_filter("gform_add_field_buttons", "ih_gform_add_field_buttons");
function ih_gform_add_field_buttons($field_groups){
unset($field_groups[2]);
unset($field_groups[3]);
$field_groups[] = array(
'name' => 'ih_fields',
'label' => 'Insurance Hero Fields',
'fields' => array(
array(
'class' => 'button',
'value' => 'Vehicle Year',
'onclick' => "StartAddField('vehicleyear');"
),
array(
'class' => 'button',
'value' => 'Vehicle Make',
'onclick' => "StartAddField('select')"
),
array(
'class' => 'button',
'value' => 'Vehicle Model',
'onclick' => "StartAddField('select')"
)
)
);
return $field_groups;
}
add_filter("gform_predefined_choices", "ih_gform_predefined_choices");
function ih_gform_predefined_choices($choices){
$choices["My New Choice"] = array("Choice 1", "Choice 2", "Choice 3");
return $choices;
}
add_filter("gform_admin_pre_render", 'ih_gform_admin_pre_render');
function ih_gform_admin_pre_render($form){
//wp_debug($form,true);
foreach($form['fields'] as $i => $field){
if($field['type'] == 'vehicleyear'){
$form['fields'][$i]['displayAllCategories'] = true;
//$form['fields'][$i]['displayCaption'] = true;
//$form['fields'][$i]['displayDescription'] = true;
//$form['fields'][$i]['displayTitle'] = true;
$form['fields'][$i]['adminLabel'] = 'Vehichle Year';
$form['fields'][$i]['adminOnly'] = false;
//$form['fields'][$i]['displayTitle'] = true;
$form['fields'][$i]['inputType'] = 'select';
$form['fields'][$i]['inputName'] = 'testingu';
$form['fields'][$i]['label'] = 'Vehicle Year';
//$form['fields'][$i]['enableChoiceValue'] = false;
$form['fields'][$i]['choices'] = array(
array (
'text' => 'My Choice',
'value' => 'My Choice',
'isSelected' => false,
'price' => '',
),
array (
'text' => 'Your Choice',
'value' => 'Your Choice',
'isSelected' => false,
'price' => '',
),
array (
'text' => 'His Choice',
'value' => 'his Choice',
'isSelected' => false,
'price' => '',
),
);
//$form['fields'][$i]['choices'] = array(1,2,3);
//$form['fields'][$i]['type'] = 'select';
}
//wp_debug($form['fields'][$i]);
}
return $form;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment