Advertisement
eventsmanager

EM Pro Forms max_input_vars fix

Sep 18th, 2015
835
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.21 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: Events Manager Pro Forms Fix
  4. Version: 1.2
  5. Plugin URI: http://wp-events-plugin.com
  6. Description: Fixes php.ini max_input_vars limitation on 24+ form fields for EM Form Builder
  7. Author: Marcus Sykes
  8. Author URI: http://wp-events-plugin.com
  9. */
  10. /*
  11.  fixing max_input_vars = 1000 limit which is preventing more than 23 custom fields
  12. data package coming in as json string in 'fields_json'
  13. stripcslashes()
  14. */
  15. class EMP_Forms_Fix{
  16.     public static function init(){
  17.         global $pagenow;
  18.         if( !empty($_REQUEST['page']) && $_REQUEST['page'] == 'events-manager-forms-editor'){
  19.             add_action('admin_init', 'EMP_Forms_Fix::post', 8, 1);
  20.             add_action('admin_head', 'EMP_Forms_Fix::js', 10, 1);
  21.         }
  22.     }
  23.    
  24.     public static function post(){
  25.         if( isset($_REQUEST['fields_json']) ){
  26.             $str = $test = str_replace(array('[]\\"','\\"', "\\'",'\\\\'),array('"','"',"'",'\\'), trim($_REQUEST['fields_json']));
  27.             $test = (array) json_decode($test);
  28.             if (count($test)) $_REQUEST = array_merge($_REQUEST, $test);
  29.         }
  30.     }
  31.    
  32.     public static function js( $form_name) {
  33.         ?>
  34.         <script type="text/javascript">
  35.             jQuery(document).ready( function($){
  36.                 if (typeof JSON.stringify != 'undefined'){
  37.                     if (typeof jQuery.serializeJSON == 'undefined') jQuery.fn.serializeJSON = function(){
  38.                         var o = {},
  39.                         a = this.serializeArray();
  40.                         jQuery.each(a, function() {
  41.                             if (o[this.name] !== undefined) {
  42.                                 if (!o[this.name].push) { o[this.name] = [o[this.name]]; }
  43.                                 o[this.name].push(this.value || '');
  44.                             } else {
  45.                                 o[this.name] = this.value || '';
  46.                             }
  47.                         });
  48.                         return JSON.stringify(o, null, 2);
  49.                     }
  50.                    
  51.                     jQuery('.em-form-custom').submit(function(event){
  52.                         var myform = jQuery(this);
  53.                         if (myform.find('#fields_json').length) return; //have already made switch, so let default submit take place
  54.                         event.preventDefault();
  55.                         var data = myform.serializeJSON();
  56.                         myform.empty().append(jQuery('<input/>').attr({id:'fields_json', name:'fields_json', value:data})).submit();
  57.                     });
  58.                 }
  59.             });
  60.         </script>
  61.         <?php  
  62.     }
  63. }
  64. if( is_admin() ){
  65.     EMP_Forms_Fix::init();
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement