Created
March 4, 2014 14:58
-
-
Save gicolek/9347955 to your computer and use it in GitHub Desktop.
GF hooks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'gform_pre_submission_1', 'gf_form_pre_submission' ); | |
/** | |
* Presubmission form handler | |
* | |
* @hook gform_pre_submission | |
*/ | |
function gf_form_pre_submission($form) { | |
// iterate over the fields to obtain specific field's id | |
foreach ( $form['fields'] as $field ) { | |
// check if the date picker class has been added | |
if ( $field['cssClass'] == 'gf-date-picker' ) { | |
// get the field id | |
$id = $field['id']; | |
// do whatever you want with the values here (change the date format, etc.) | |
$_POST['input_' . $id] = $_POST['input_' . $id]; | |
} | |
} | |
} | |
add_filter( "gform_field_validation_1", 'gf_custom_validation', 10, 4 ); | |
/** | |
* Presubmission form handler | |
* | |
* @hook gform_pre_submission | |
*/ | |
/** | |
* Custom GF validation function used for pagination and required fields | |
* | |
* @return string | |
*/ | |
function gf_custom_validation($result, $value, $form, $field) { | |
// lets validate only our custom field | |
if ( $field['cssClass'] === 'gf-date-picker' ) { | |
// let's obtain separate strings for each part of the date | |
$value = array_map( 'intval', explode( '/', $value ) ); | |
// if the field is not valid then return the user | |
if ( !checkdate( $value[0], $value[1], $value[2] ) ) { | |
// add error message to the end user | |
$result["is_valid"] = false; | |
$result["message"] = "Wrong date, please check the format and make sure it's a valid one. "; | |
} else { | |
$result["is_valid"] = true; | |
} | |
} | |
return $result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment