@@ -22,3 +22,45 @@ submit and change the settings on the server. It does this by counting how many
22
22
will be submitted in a form (it does this, hopefully, intellidently by taking into account
23
23
all the form item types and selected values). The plugin is given the maximum number of
24
24
items the server will accept when the page is generated, so it has a number to compare to.
25
+
26
+ The simplest way to implement the check is to use this JavaScript in the jQuery ready()
27
+ function:
28
+
29
+ $('form').maxSubmit({max_count: 1000});
30
+
31
+ That will trigger on all forms, and warn the user if more than 1000 values are about to
32
+ be POSTed by the form. Additional settings allow you to modify the confirm box text,
33
+ or replace the standard confirm box with something more ambitious, such as a jquery.ui
34
+ dialog. You can target specific forms with different settings if you wish.
35
+
36
+ The server limit (1000 in this case) needs to be passed into the script above. This can
37
+ be found with a simple function like this:
38
+
39
+ /**
40
+ * Get the submission limit.
41
+ * Returns the lowest limit or false if no limit can be found.
42
+ * An alternate default can be provided if required.
43
+ * CHECKME: do we need to separate GET and POST limits, as they may apply
44
+ * to different forms. The larger number of parameters is like to only
45
+ * apply to POST forms, so POST is important. The REQUEST max vars is
46
+ * another thing to consider, as it will be the sum of GET and POST parameters.
47
+ */
48
+ function getFormSubmissionLimit($default = false)
49
+ {
50
+ // All these ini settings will affect the number of parameters that can be
51
+ // processed. Check them all to find the lowest.
52
+ $ini = array();
53
+ $ini[] = ini_get('max_input_vars');
54
+ $ini[] = ini_get('suhosin.get.max_vars');
55
+ $ini[] = ini_get('suhosin.post.max_vars');
56
+ $ini[] = ini_get('suhosin.request.max_vars');
57
+
58
+ $ini = array_filter($ini, 'is_numeric');
59
+
60
+ $lowest_limit = min($ini);
61
+
62
+ return ($lowest_limit === false ? $default : $lowest_limit);
63
+ }
64
+
65
+ That runs on the server and provides the server settings to insert into the JavaScript
66
+ initialisation, and will return 1000 by default on most PHP servers.
0 commit comments