Created
April 12, 2012 09:51
Revisions
-
Bronson Quick revised this gist
May 22, 2012 . 1 changed file with 4 additions and 4 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -16,7 +16,7 @@ function custom_validation($validation_result) //We need to loop through all the form fields to check if the value matches and of the default values foreach ($form['fields'] as &$field) { //Check if the value is equal to the Default Value you entered in Gravity Forms if ($field["value"] === "Your name") { // set the form validation to false $validation_result["is_valid"] = false; //The field ID can be found by hovering over the field in the backend of WordPress @@ -25,7 +25,7 @@ function custom_validation($validation_result) $field["validation_message"] = "Please enter your name."; } } if ($field["value"] === "Job Title") { // set the form validation to false $validation_result["is_valid"] = false; //The field ID can be found by hovering over the field in the backend of WordPress @@ -34,7 +34,7 @@ function custom_validation($validation_result) $field["validation_message"] = "Please enter your job title."; } } if ($field["value"] === "Contact phone number") { // set the form validation to false $validation_result["is_valid"] = false; //The field ID can be found by hovering over the field in the backend of WordPress @@ -43,7 +43,7 @@ function custom_validation($validation_result) $field["validation_message"] = "Please enter your contact phone number."; } } if ($field["value"] === "Company") { // set the form validation to false $validation_result["is_valid"] = false; //The field ID can be found by hovering over the field in the backend of WordPress -
Bronson Quick revised this gist
Apr 12, 2012 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -8,7 +8,7 @@ function change_validation_message($message, $form) // Often forms in Gravity Forms to need to start with default values and we need to check the form in case the user hasn't entered new data and give them a validation message back // Append the Gravity Forms ID to the end of the filter so that the validation only runs on this form. In this example I'm doing it on Form #2 add_filter('gform_validation_2', 'custom_validation'); function custom_validation($validation_result) { -
Bronson Quick created this gist
Apr 12, 2012 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,59 @@ <?php //This is a filter to change the default validation message that Gravity Forms generates add_filter('gform_validation_message', 'change_validation_message', 10, 2); function change_validation_message($message, $form) { return "<div class='validation_error'><strong>Oops!</strong> Looks like there’s something wrong. Please review the form above.</div>"; } // Often forms in Gravity Forms to need to start with default values and we need to check the form in case the user hasn't entered new data and give them a validation message back // Append the Gravity Forms ID to the end of the filter so that the validation only runs on this form add_filter('gform_validation_2', 'custom_validation'); function custom_validation($validation_result) { $form = $validation_result["form"]; //We need to loop through all the form fields to check if the value matches and of the default values foreach ($form['fields'] as &$field) { //Check if the value is equal to the Default Value you entered in Gravity Forms if ($field["value"] = "Your name") { // set the form validation to false $validation_result["is_valid"] = false; //The field ID can be found by hovering over the field in the backend of WordPress if ($field["id"] == "2") { $field["failed_validation"] = true; $field["validation_message"] = "Please enter your name."; } } if ($field["value"] = "Job Title") { // set the form validation to false $validation_result["is_valid"] = false; //The field ID can be found by hovering over the field in the backend of WordPress if ($field["id"] == "4") { $field["failed_validation"] = true; $field["validation_message"] = "Please enter your job title."; } } if ($field["value"] = "Contact phone number") { // set the form validation to false $validation_result["is_valid"] = false; //The field ID can be found by hovering over the field in the backend of WordPress if ($field["id"] == "5") { $field["failed_validation"] = true; $field["validation_message"] = "Please enter your contact phone number."; } } if ($field["value"] = "Company") { // set the form validation to false $validation_result["is_valid"] = false; //The field ID can be found by hovering over the field in the backend of WordPress if ($field["id"] == "6") { $field["failed_validation"] = true; $field["validation_message"] = "Please enter your company name."; } } } //Assign modified $form object back to the validation result $validation_result["form"] = $form; return $validation_result; }?>