Advertisement
brook-tribe

Fix for themes that erroneously submit placeholder text

Mar 26th, 2014
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.27 KB | None | 0 0
  1. /*
  2.  This snippet is intended to fix themes that override form
  3.  submissions and include placeholder text in the data submitted.
  4.  Add this to your theme's functions.php file.
  5.  */
  6.  
  7. function hide_tribe_placeholders($before) {
  8.     $before .= '
  9. <script type="text/javascript">
  10.     jQuery(document).ajaxStart(function(){
  11.         // Hides placeholder text for each element to prevent its submission
  12.         jQuery(".tribe-bar-filters-inner input").each(function(){
  13.             _self = jQuery(this);
  14.  
  15.             // Check to see if the value = placeholder value, clear it if so
  16.             // Some themes set the value from the placeholder, causing erroneous data to submit
  17.             if(_self.val() == _self.attr("placeholder"))
  18.                 _self.val("");
  19.  
  20.             // Store placeholder text in data, then clear placeholder
  21.             jQuery.data(this, "tribe-placeholder", _self.attr("placeholder"));
  22.             _self.attr("placeholder", "");
  23.         });
  24.     }).ajaxComplete(function(){
  25.         // Shows placeholder text now that submission is complete
  26.         jQuery(".tribe-bar-filters-inner input").each(function(){
  27.             ptext = jQuery.data(this, "tribe-placeholder");
  28.             if(typeof ptext === "string" && ptext != "")
  29.                 jQuery(this).attr("placeholder", ptext);
  30.         });
  31.     });
  32. </script>';
  33.  
  34.     return $before;
  35. }
  36. add_filter( 'tribe_events_before_html', 'hide_tribe_placeholders');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement