PDA

View Full Version : Submitting form fields to a database - is this an OK way to do it?



kevin-berry
28 Jun 2010, 3:22 PM
I have a form that has expandable fieldsets, and inside those fieldsets are some related options. So when the user clicks Submit, I just gather up all the information in the form by the id's that I've assigned to everything. Is this the "right" way to go about gathering up form data in an ExtJS form? Here's my code for the submit button:



var default_buttons =
[{
text: 'Create Form',
handler: function()
{

///////////////////////////////////////////////////////////
/// START BY RETRIEVING ALL THE DATA IN THE FORM ///
///////////////////////////////////////////////////////////

//retrieve form title
var form_name = Ext.getCmp('form_name').getValue();

//retrieve parent sub id node data
var parent_sub_id_isChecked = Ext.get('parent_sub_id_checkbox_toggle').dom.checked;
var pid_aux_text = Ext.getCmp('pid_aux_text').getValue();
var pid_rank = Ext.getCmp('pid_rank').getValue();
var pid_searchable_isChecked = Ext.get('pid_searchable').dom.checked;

//retrieve assign_sub_perm node data
var assign_sub_perm_isChecked = Ext.get('sub_perm_checkbox_toggle').dom.checked;
var sub_perm_aux_text = Ext.getCmp('sub_perm_aux_text').getValue();
var sub_perm_rank = Ext.getCmp('sub_perm_rank').getValue();
var sub_perm_searchable_isChecked = Ext.get('sub_perm_searchable').dom.checked;

//retrieve add_files node data
var add_files_isChecked = Ext.get('add_files_checkbox_toggle').dom.checked;
var add_files_aux_text = Ext.getCmp('add_files_aux_text').getValue();
var add_files_rank = Ext.getCmp('add_files_rank').getValue();
var add_files_searchable_isChecked = Ext.get('add_files_searchable').dom.checked;

//retrieve textbox_elems node data
var textbox_elems_isChecked = Ext.get('textbox_elems_checkbox_toggle').dom.checked;
var textbox_elems_title = Ext.getCmp('textbox_elems_title').getValue();
var textbox_elems_aux_txt = Ext.getCmp('textbox_elems_aux_text').getValue();
var textbox_elems_rnk = Ext.getCmp('textbox_elems_rank').getValue();
var textbox_elems_searchable_isChecked = Ext.get('textbox_elems_searchable').dom.checked;

//retrieve groupcheck elems node data
var groupcheck_isChecked = Ext.get('groupcheck_checkbox_toggle').dom.checked;
var groupcheck_title = Ext.getCmp('groupcheck_title').getValue();
var groupcheck_aux_txt = Ext.getCmp('groupcheck_aux_text').getValue();
var groupcheck_rnk = Ext.getCmp('groupcheck_rank').getValue();
var groupcheck_searchable_isChecked = Ext.get('groupcheck_searchable').dom.checked;

///////////////////////////////////////////////////
/// (LET IT BE) KNOWN WHAT IS ON THE FORM ///
///////////////////////////////////////////////////

var nodes = "";

//Print any PID data
if(parent_sub_id_isChecked) { nodes += "\nParent Submission ID"; }
if(pid_aux_text != "") { nodes += "\nAuxiliary Text : " + pid_aux_text; }
if(pid_searchable_isChecked) { nodes += "\n- searchable"; }
if(parent_sub_id_isChecked) { nodes += "\n- rank (" + pid_rank + ")"; }

//Print any Sub_Perm data
if(assign_sub_perm_isChecked) { nodes += "\nAssign Submission Permissions"; }
if(sub_perm_aux_text != "") { nodes += "\nAuxiliary Text : " + sub_perm_aux_text; }
if(sub_perm_searchable_isChecked) { nodes += "\n- searchable"; }
if(assign_sub_perm_isChecked) { nodes += "\n- rank (" + sub_perm_rank + ")"; }

//Print any Add Files data
if(add_files_isChecked) { nodes += "\nAdd Files"; }
if(add_files_aux_text != "") { nodes += "\nAuxiliary Text : " + add_files_aux_text; }
if(add_files_searchable_isChecked) { nodes += "\n- searchable"; }
if(add_files_isChecked) { nodes += "\n- rank (" + add_files_rank + ")"; }

//Print any Textbox Elems data
if(textbox_elems_isChecked) { nodes += "\nTextbox(es)"; }
if(textbox_elems_title != "") { nodes += "\nTitle : " + textbox_elems_title; }
if(textbox_elems_aux_txt != "") { nodes += "\nAuxiliary Text : " + textbox_elems_aux_txt;}
if(textbox_elems_searchable_isChecked) { nodes += "\n- searchable"; }
if(textbox_elems_isChecked) { nodes += "\n- rank (" + textbox_elems_rnk + ")"; }

//Print any Group Check data
if(groupcheck_isChecked) { nodes += "\nGroup Check(s)"; }
if(groupcheck_title != "") { nodes += "\nTitle : " + groupcheck_title; }
if(groupcheck_aux_txt != "") { nodes += "\nAuxiliary Text : " + groupcheck_aux_txt; }
if(groupcheck_searchable_isChecked) { nodes += "\n- searchable"; }
if(groupcheck_isChecked) { nodes += "\n- rank (" + groupcheck_rnk + ")"; }

alert("Attemping to create form : " + form_name + "\n\nWith the following nodes:\n" + nodes);

var post_params = "ajax_action=check_form_name&form_name=" + form_name;
create_http_request();
alert("Sending request...");
send_http_request(handler_check_form_name, "POST", target_url, post_params);
}

}];