Created
July 3, 2014 16:41
-
-
Save karlazz/e207417e5165f49bee1d to your computer and use it in GitHub Desktop.
Some gravity form field manipulations: character counter (requires plugin), field validations, preset form values, post set form value.
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('wp_footer', 'add_char_counter'); | |
| function add_char_counter() { | |
| if ( is_page( array( 'add-a-highlight', 'add-a-publication' ) ) ) { ?> | |
| <script src="/wp-content/themes/ameriflux/library/js/textcounter.min.js"></script> | |
| <script type="text/javascript"> | |
| jQuery('.amx-title input').textcounter({ | |
| max: 250, | |
| countDownText: "Characters Left: " | |
| }); | |
| jQuery('.amx-descrip textarea').textcounter({ | |
| max: 1000, | |
| countDownText: "Characters Left: " | |
| }); | |
| </script> | |
| <?php } | |
| } | |
| add_action('wp_footer', 'makeyear'); | |
| function makeyear() { | |
| if ( is_page( array( 'send', 'add-a-highlight', 'add-a-publication' ) ) ) { ?> | |
| <script type="text/javascript"> | |
| jQuery('.amx-pubdate input').on('change', function() { | |
| var xdate=jQuery('.amx-pubdate input').val().substr(0,4); | |
| jQuery('.amx-pubyear input').val(xdate); | |
| }); | |
| </script> | |
| <?php } | |
| } | |
| add_filter("gform_field_validation_4_10", "pageno_validation", 10, 4); | |
| function pageno_validation($result, $value, $form, $field){ | |
| $parts=explode("-",$value); | |
| if (count($parts) != 2) $result["is_valid"] = false; | |
| if( ! $result["is_valid"] ){ | |
| $result["message"] = "Please enter start and end pages eg: 985-1000"; | |
| } | |
| return $result; | |
| } | |
| add_filter("gform_field_validation_4_11", "pubdate_validation", 10, 4); | |
| function pubdate_validation($result, $value, $form, $field){ | |
| $parts=explode("/",$value); | |
| $count=count($parts); | |
| if ($parts[0]<1900 && $parts[0]>2020) $result["is_valid"] = false; | |
| else if ($count>1 && $parts[1]>13) $result["is_valid"] = false; | |
| else if ($count>2 && $parts[2]>31) $result["is_valid"] = false; | |
| if( ! $result["is_valid"] ){ | |
| $result["message"] = "Please enter a valid date YYYY or YYYY/MM or YYYY/MM/DD"; | |
| } | |
| return $result; | |
| } | |
| //add_filter("gform_save_field_value", "save_field_value", 10, 4); | |
| function save_field_value($value, $lead, $field, $form){ | |
| if(absint($form["id"]) <> 5) | |
| return $value; | |
| if ($field["id"]==3) | |
| return 2001; | |
| else | |
| return $value; | |
| } | |
| //add_filter("gform_field_value_fonty", "set_field_value", 10, 4); | |
| function set_field_value(){ | |
| /* prepopulate a field with advanced tab dynamic load parameter=fonty */ | |
| return 2005; | |
| } | |
| /* | |
| function custom_validation($validation_result){ | |
| ?> | |
| <script type='text/javascript'> | |
| console.log("Working"); | |
| </script> | |
| <?php | |
| return $validation_result; | |
| } | |
| add_filter('gform_validation', 'custom_validation'); | |
| */ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment