[Phpmyadmin-git] [SCM] phpMyAdmin branch, master, updated. RELEASE_3_4_0BETA3-1815-gdfa4668
Marc Delisle
lem9 at users.sourceforge.net
Sun Mar 6 14:31:19 CET 2011
The branch, master has been updated
via dfa4668fe6d814e9a008bde1ed343d2eb60de680 (commit)
from 1b94d12c3e00fae78cc8042e1628a80ef5f817b7 (commit)
- Log -----------------------------------------------------------------
commit dfa4668fe6d814e9a008bde1ed343d2eb60de680
Author: Marc Delisle <marc at infomarc.info>
Date: Sun Mar 6 08:30:51 2011 -0500
Bug #3187422 Form validation and submission
-----------------------------------------------------------------------
Summary of changes:
js/functions.js | 141 +++++++++++++++++++++-----------------
libraries/tbl_properties.inc.php | 3 +-
2 files changed, 80 insertions(+), 64 deletions(-)
diff --git a/js/functions.js b/js/functions.js
index eae4b27..62ac60c 100644
--- a/js/functions.js
+++ b/js/functions.js
@@ -1738,7 +1738,7 @@ $(document).ready(function() {
*
*/
// .live() must be called after a selector, see http://api.jquery.com/live
- $("#create_table_form.ajax input[name=do_save_data]").live('click', function(event) {
+ $("#create_table_form input[name=do_save_data]").live('click', function(event) {
event.preventDefault();
/**
@@ -1746,71 +1746,88 @@ $(document).ready(function() {
*/
var $form = $("#create_table_form");
- PMA_ajaxShowMessage(PMA_messages['strProcessingRequest']);
- if (! $form.find('input:hidden').is('#ajax_request_hidden')) {
- $form.append('<input type="hidden" id="ajax_request_hidden" name="ajax_request" value="true" />');
- }
- //User wants to submit the form
- $.post($form.attr('action'), $form.serialize() + "&do_save_data=" + $(this).val(), function(data) {
- if(data.success == true) {
- $('#properties_message').html('');
- PMA_ajaxShowMessage(data.message);
- // Only if the create table dialog (distinct panel) exists
- if ($("#create_table_dialog").length > 0) {
- $("#create_table_dialog").dialog("close").remove();
- }
-
- /**
- * @var tables_table Object referring to the <tbody> element that holds the list of tables
- */
- var tables_table = $("#tablesForm").find("tbody").not("#tbl_summary_row");
- // this is the first table created in this db
- if (tables_table.length == 0) {
- if (window.parent && window.parent.frame_content) {
- window.parent.frame_content.location.reload();
- }
- } else {
- /**
- * @var curr_last_row Object referring to the last <tr> element in {@link tables_table}
- */
- var curr_last_row = $(tables_table).find('tr:last');
- /**
- * @var curr_last_row_index_string String containing the index of {@link curr_last_row}
- */
- var curr_last_row_index_string = $(curr_last_row).find('input:checkbox').attr('id').match(/\d+/)[0];
- /**
- * @var curr_last_row_index Index of {@link curr_last_row}
- */
- var curr_last_row_index = parseFloat(curr_last_row_index_string);
- /**
- * @var new_last_row_index Index of the new row to be appended to {@link tables_table}
- */
- var new_last_row_index = curr_last_row_index + 1;
- /**
- * @var new_last_row_id String containing the id of the row to be appended to {@link tables_table}
- */
- var new_last_row_id = 'checkbox_tbl_' + new_last_row_index;
-
- //append to table
- $(data.new_table_string)
- .find('input:checkbox')
- .val(new_last_row_id)
- .end()
- .appendTo(tables_table);
-
- //Sort the table
- $(tables_table).PMA_sort_table('th');
- }
+ /*
+ * First validate the form; if there is a problem, avoid submitting it
+ *
+ * checkTableEditForm() needs a pure element and not a jQuery object,
+ * this is why we pass $form[0] as a parameter (the jQuery object
+ * is actually an array of DOM elements)
+ */
- //Refresh navigation frame as a new table has been added
- if (window.parent && window.parent.frame_navigation) {
- window.parent.frame_navigation.location.reload();
+ if (checkTableEditForm($form[0], $form.find('input[name=orig_num_fields]').val())) {
+ // OK, form passed validation step
+ if ($form.hasClass('ajax')) {
+ PMA_ajaxShowMessage(PMA_messages['strProcessingRequest']);
+ if (! $form.find('input:hidden').is('#ajax_request_hidden')) {
+ $form.append('<input type="hidden" id="ajax_request_hidden" name="ajax_request" value="true" />');
}
- }
+ //User wants to submit the form
+ $.post($form.attr('action'), $form.serialize() + "&do_save_data=" + $(this).val(), function(data) {
+ if(data.success == true) {
+ $('#properties_message').html('');
+ PMA_ajaxShowMessage(data.message);
+ // Only if the create table dialog (distinct panel) exists
+ if ($("#create_table_dialog").length > 0) {
+ $("#create_table_dialog").dialog("close").remove();
+ }
+
+ /**
+ * @var tables_table Object referring to the <tbody> element that holds the list of tables
+ */
+ var tables_table = $("#tablesForm").find("tbody").not("#tbl_summary_row");
+ // this is the first table created in this db
+ if (tables_table.length == 0) {
+ if (window.parent && window.parent.frame_content) {
+ window.parent.frame_content.location.reload();
+ }
+ } else {
+ /**
+ * @var curr_last_row Object referring to the last <tr> element in {@link tables_table}
+ */
+ var curr_last_row = $(tables_table).find('tr:last');
+ /**
+ * @var curr_last_row_index_string String containing the index of {@link curr_last_row}
+ */
+ var curr_last_row_index_string = $(curr_last_row).find('input:checkbox').attr('id').match(/\d+/)[0];
+ /**
+ * @var curr_last_row_index Index of {@link curr_last_row}
+ */
+ var curr_last_row_index = parseFloat(curr_last_row_index_string);
+ /**
+ * @var new_last_row_index Index of the new row to be appended to {@link tables_table}
+ */
+ var new_last_row_index = curr_last_row_index + 1;
+ /**
+ * @var new_last_row_id String containing the id of the row to be appended to {@link tables_table}
+ */
+ var new_last_row_id = 'checkbox_tbl_' + new_last_row_index;
+
+ //append to table
+ $(data.new_table_string)
+ .find('input:checkbox')
+ .val(new_last_row_id)
+ .end()
+ .appendTo(tables_table);
+
+ //Sort the table
+ $(tables_table).PMA_sort_table('th');
+ }
+
+ //Refresh navigation frame as a new table has been added
+ if (window.parent && window.parent.frame_navigation) {
+ window.parent.frame_navigation.location.reload();
+ }
+ } else {
+ $('#properties_message').html(data.error);
+ }
+ }) // end $.post()
+ } // end if ($form.hasClass('ajax')
else {
- $('#properties_message').html(data.error);
+ // non-Ajax submit
+ $form.append('<input type="hidden" name="do_save_data" value="save" />');
+ $form.submit();
}
- }) // end $.post()
+ } // end if (checkTableEditForm() )
}) // end create table form (save)
/**
diff --git a/libraries/tbl_properties.inc.php b/libraries/tbl_properties.inc.php
index 14e4936..54e9d1d 100644
--- a/libraries/tbl_properties.inc.php
+++ b/libraries/tbl_properties.inc.php
@@ -774,8 +774,7 @@ if ($action == 'tbl_create.php') {
?>
<fieldset class="tblFooters">
- <input type="submit" name="do_save_data" value="<?php echo __('Save'); ?>"
- onclick="return checkTableEditForm(this.form, <?php echo $num_fields; ?>)" />
+ <input type="submit" name="do_save_data" value="<?php echo __('Save'); ?>" />
<?php if ($action == 'tbl_create.php' || $action == 'tbl_addfield.php') { ?>
<?php echo __('Or'); ?>
<?php echo sprintf(__('Add %s column(s)'), '<input type="text" id="added_fields" name="added_fields" size="2" value="1" onfocus="this.select()" />'); ?>
hooks/post-receive
--
phpMyAdmin
More information about the Git
mailing list