Skip to content

Commit

Permalink
Fixes for ticket #1
Browse files Browse the repository at this point in the history
  • Loading branch information
judgej committed Jan 27, 2014
1 parent f2bdda2 commit 14fba48
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 13 deletions.
44 changes: 39 additions & 5 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script type="text/javascript" src="jquery.maxsubmit.js"></script>

<!-- Here the application could pass in a translated message suitable for the language of the end user -->
<script type="text/javascript">
jQuery(document).ready(function($) {
$('form#form1').maxSubmit({
Expand All @@ -19,18 +21,36 @@
});
});
</script>

<!-- Some fancy stuff for the demo -->
<script type="text/javascript">
jQuery(document).ready(function($) {
/* Toggle the enabled state on some form items */
$('.text_label, .radio_label, .select_label').click(function() {
return $(this).siblings('input, select, textarea').each(function(){
this.disabled = !this.disabled;
});
});
});
</script>

<style type="text/css">
.text_label, .radio_label, .select_label, .doc_label {cursor: pointer; border-bottom: green dotted 1px;}
</style>
</head>

<?php
// Read any submitted data to go back into the form.
$input = array(
'text1' => 'Text 1',
'text2' => 'Text 2',
'textarea1' => "A nice\nstory.",
'checkbox1' => 'on',
'checkbox2' => '',
);

foreach($input as $key => $value) {
$input[$key] = (isset($_POST[$key]) ? $_POST[$key] : '' );
$input[$key] = (isset($_POST[$key]) ? htmlspecialchars($_POST[$key]) : $input[$key] );
}

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

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

<p>
Clicking the labels of <span class="doc_label">the form items like this</span> will disable those items, so they are not submitted.
</p>

<form method="post" id="form1">
<h2>Mandatory form items: will count as one submitted parameter each</h2>

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

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

<p>
<textarea rows="3" cols="15" name="textarea1"><?php echo $input['textarea1']; ?></textarea>
<span class="text_label" title="Click to toggle toggle the enabled state">(counts as one parameter)</span>
</p>

<p>
<select name="select2">
<option value="value1">Value 1</option>
<option value="value2">Value 2</option>
</select>
<span class="select_label" title="Click to toggle toggle the enabled state">(counts as one parameter)</span>
</p>

<p>
<input type="radio" name="radio1" value="value1" checked />
<input type="radio" name="radio1" value="value2" />
<input type="radio" name="radio1" value="value3" />
Radio 1
<span class="radio_label" title="Click to toggle toggle the enabled state">Radio 1</apan>
</p>

<p>
<input type="radio" name="radio2" value="value1" checked />
<input type="radio" name="radio2" value="value2" />
<input type="radio" name="radio2" value="value3" />
Radio 2
<span class="radio_label" title="Click to toggle toggle the enabled state">Radio 2</apan>
</p>

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

<p>
Expand Down
2 changes: 1 addition & 1 deletion jquery-maxsubmit.jquery.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"maxinputvars",
"suhosin"
],
"version": "1.0.2",
"version": "1.1.0",
"author": {
"name": "Jason Judge",
"url": "https://github.com/judgej"
Expand Down
15 changes: 8 additions & 7 deletions jquery.maxsubmit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Copyright 2013-2014 Academe Computing Ltd
* Released under the MIT license
* Author: Jason Judge <jason@academe.co.uk>
* Version: 1.0.2
* Version: 1.1.0
*/
/**
* jquery.maxsubmit.js
Expand Down Expand Up @@ -34,7 +34,8 @@
// Can use {max_count} as a placeholder for the permitted maximum
// and {form_count} for the counted form items.

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

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

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

// Checkboxes will post only if checked.
$('input:checkbox', this).each(function() {
$('input:checkbox:enabled', this).each(function() {
if (this.checked) form_count++;
});

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

// Multi-select lists will post one parameter for each selected item.
$('select[multiple]', this).each(function() {
$('select:enabled[multiple]', this).each(function() {
// The select item value is null if no options are selected.
var select = $(this).val();
if (select !== null) form_count += select.length;
Expand All @@ -82,7 +83,7 @@
// Each radio button group will post one parameter.
// Count the radio groups
var rgroups = [];
$('input:radio').each(function(index, el) {
$('input:enabled:radio').each(function(index, el) {
var i;
for(i = 0; i < rgroups.length; i++) {
if (rgroups[i] == $(el).attr('name')) return;
Expand Down

0 comments on commit 14fba48

Please sign in to comment.