Skip to content

Commit 14fba48

Browse files
committed
Fixes for ticket #1
1 parent f2bdda2 commit 14fba48

File tree

3 files changed

+48
-13
lines changed

3 files changed

+48
-13
lines changed

index.php

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
1111
<script type="text/javascript" src="jquery.maxsubmit.js"></script>
12+
13+
<!-- Here the application could pass in a translated message suitable for the language of the end user -->
1214
<script type="text/javascript">
1315
jQuery(document).ready(function($) {
1416
$('form#form1').maxSubmit({
@@ -19,18 +21,36 @@
1921
});
2022
});
2123
</script>
24+
25+
<!-- Some fancy stuff for the demo -->
26+
<script type="text/javascript">
27+
jQuery(document).ready(function($) {
28+
/* Toggle the enabled state on some form items */
29+
$('.text_label, .radio_label, .select_label').click(function() {
30+
return $(this).siblings('input, select, textarea').each(function(){
31+
this.disabled = !this.disabled;
32+
});
33+
});
34+
});
35+
</script>
36+
37+
<style type="text/css">
38+
.text_label, .radio_label, .select_label, .doc_label {cursor: pointer; border-bottom: green dotted 1px;}
39+
</style>
2240
</head>
2341

2442
<?php
43+
// Read any submitted data to go back into the form.
2544
$input = array(
2645
'text1' => 'Text 1',
2746
'text2' => 'Text 2',
47+
'textarea1' => "A nice\nstory.",
2848
'checkbox1' => 'on',
2949
'checkbox2' => '',
3050
);
3151

3252
foreach($input as $key => $value) {
33-
$input[$key] = (isset($_POST[$key]) ? $_POST[$key] : '' );
53+
$input[$key] = (isset($_POST[$key]) ? htmlspecialchars($_POST[$key]) : $input[$key] );
3454
}
3555

3656
$input = array_merge(
@@ -88,7 +108,7 @@ function getFormSubmissionLimit($default = false)
88108
<?php if (!empty($_POST)) : ?>
89109
<p style="border-radius: 4px; border: 2px solid #ff3333; padding: 1em; background-color: #fdeaaa">
90110
Thank you for posting some stuff!
91-
On a real application you may have lost some data by doing so.
111+
On a real application you may have lost some data by ignoring the warning.
92112
</p>
93113
<?php endif; ?>
94114

@@ -97,35 +117,48 @@ function getFormSubmissionLimit($default = false)
97117
For these tests, we will set the limit to 2, so the confirm message is always shown.
98118
</p>
99119

120+
<p>
121+
Clicking the labels of <span class="doc_label">the form items like this</span> will disable those items, so they are not submitted.
122+
</p>
123+
100124
<form method="post" id="form1">
101125
<h2>Mandatory form items: will count as one submitted parameter each</h2>
102126

103127
<p>
104128
<input type="text" name="text1" value="<?php echo $input['text1']; ?>" />
129+
<span class="text_label" title="Click to toggle toggle the enabled state">(counts as one parameter)</span>
105130
</p>
106131

107132
<p>
108133
<input type="text" name="text2" value="<?php echo $input['text2']; ?>" />
134+
<span class="text_label" title="Click to toggle toggle the enabled state">(counts as one parameter)</span>
135+
</p>
136+
137+
<p>
138+
<textarea rows="3" cols="15" name="textarea1"><?php echo $input['textarea1']; ?></textarea>
139+
<span class="text_label" title="Click to toggle toggle the enabled state">(counts as one parameter)</span>
109140
</p>
110141

111142
<p>
112143
<select name="select2">
113144
<option value="value1">Value 1</option>
145+
<option value="value2">Value 2</option>
114146
</select>
147+
<span class="select_label" title="Click to toggle toggle the enabled state">(counts as one parameter)</span>
115148
</p>
116149

117150
<p>
118151
<input type="radio" name="radio1" value="value1" checked />
119152
<input type="radio" name="radio1" value="value2" />
120153
<input type="radio" name="radio1" value="value3" />
121-
Radio 1
154+
<span class="radio_label" title="Click to toggle toggle the enabled state">Radio 1</apan>
122155
</p>
123156

124157
<p>
125158
<input type="radio" name="radio2" value="value1" checked />
126159
<input type="radio" name="radio2" value="value2" />
127160
<input type="radio" name="radio2" value="value3" />
128-
Radio 2
161+
<span class="radio_label" title="Click to toggle toggle the enabled state">Radio 2</apan>
129162
</p>
130163

131164
<hr />
@@ -145,7 +178,8 @@ function getFormSubmissionLimit($default = false)
145178
<?php foreach($input['select1'] as $key => $value) { ?>
146179
<option value="<?php echo "$key"; ?>" <?php echo ($value ? "selected='selected'" : "") ?>><?php echo $key; ?></option>
147180
<?php } ?>
148-
</select> (counts as up to three parameters)
181+
</select>
182+
<span class="select_label" title="Click to toggle toggle the enabled state">(counts as up to three parameters)</span>
149183
</p>
150184

151185
<p>

jquery-maxsubmit.jquery.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"maxinputvars",
88
"suhosin"
99
],
10-
"version": "1.0.2",
10+
"version": "1.1.0",
1111
"author": {
1212
"name": "Jason Judge",
1313
"url": "https://github.com/judgej"

jquery.maxsubmit.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Copyright 2013-2014 Academe Computing Ltd
33
* Released under the MIT license
44
* Author: Jason Judge <[email protected]>
5-
* Version: 1.0.2
5+
* Version: 1.1.0
66
*/
77
/**
88
* jquery.maxsubmit.js
@@ -34,7 +34,8 @@
3434
// Can use {max_count} as a placeholder for the permitted maximum
3535
// and {form_count} for the counted form items.
3636

37-
max_exceeded_message: 'This form has too many fields for the server to accept.\n'
37+
max_exceeded_message:
38+
'This form has too many fields for the server to accept.\n'
3839
+ ' Data may be lost if you submit. Are you sure you want to go ahead?',
3940

4041
// The function that will display the confirm message.
@@ -60,20 +61,20 @@
6061
// submitted to the server.
6162

6263
// Text fields and submit buttons will all post one parameter.
63-
var form_count = $('input:text, input:submit, input:password, textarea', this).length;
64+
var form_count = $('input:text:enabled, input:submit:enabled, input:password:enabled, textarea:enabled', this).length;
6465

6566
// Checkboxes will post only if checked.
66-
$('input:checkbox', this).each(function() {
67+
$('input:checkbox:enabled', this).each(function() {
6768
if (this.checked) form_count++;
6869
});
6970

7071
// Single-select lists will always post one value.
71-
$('select:not([multiple])', this).each(function() {
72+
$('select:enabled:not([multiple])', this).each(function() {
7273
form_count++;
7374
});
7475

7576
// Multi-select lists will post one parameter for each selected item.
76-
$('select[multiple]', this).each(function() {
77+
$('select:enabled[multiple]', this).each(function() {
7778
// The select item value is null if no options are selected.
7879
var select = $(this).val();
7980
if (select !== null) form_count += select.length;
@@ -82,7 +83,7 @@
8283
// Each radio button group will post one parameter.
8384
// Count the radio groups
8485
var rgroups = [];
85-
$('input:radio').each(function(index, el) {
86+
$('input:enabled:radio').each(function(index, el) {
8687
var i;
8788
for(i = 0; i < rgroups.length; i++) {
8889
if (rgroups[i] == $(el).attr('name')) return;

0 commit comments

Comments
 (0)