Here is what I am trying to put together:
Form 1 has two dropdown fields, one of which is which state do you live in?
I would like to set the dropdown for state on form 1 to redirect to a specific url based on the state the user selects.
There are 50 pages containing a different form 2, a page for each state with a unique form. The page slug for these corresponding pages are each state's 2 letter abbreviation.
Need to target dropdown field to validate based on css class assigned.
Target dropdown contains US states.
Each state triggers a gorm_confirmation to redirect to site_url(CUSTOM) ELSE a static redirect url if no match.
Dynamically build site_url(CUSTOM) where (CUSTOM) = /2 letter state code (the value selected in the state dropdown field)
Match US state selected in dropdown on form 1 to the site_url(CUSTOM) and redirect.
basically matching the dropdown field value to the page slug for redirect.
To target this validation and confirmation I would like to add a css class to the field and thought the code below (found in the forum here for vin number validation) would allow.
1 - Tie our validation function to the 'gform_validation' hook
add_filter('gform_validation', 'state-redirect');
function state_redirect($validation_result) {
// 2 - Get the form object from the validation result
$form = $validation_result["form"];
// 3 - Get the current page being validated
$current_page = rgpost('gform_source_page_number_' . $form['id']) ? rgpost('gform_source_page_number_' . $form['id']) : 1;
// 4 - Loop through the form fields
foreach($form['fields'] as &$field){
// 5 - If the field does not have our designated CSS class, skip it
if(strpos($field['cssClass'], 'validate-vin') === false)
continue;
// 6 - Get the field's page number
$field_page = $field['pageNumber'];
// 7 - Check if the field is hidden by GF conditional logic
$is_hidden = RGFormsModel::is_field_hidden($form, $field, array());
// 8 - If the field is not on the current page OR if the field is hidden, skip it
if($field_page != $current_page || $is_hidden)
continue;
// 9 - Get the submitted value from the $_POST
$field_value = rgpost("input_{$field['id']}");
// 10 - Make a call to your validation function to validate the value
$is_valid = is_state($field_value);
Any help would be greatly appreciated!
Posted 11 years ago on Wednesday May 29, 2013 |
Permalink