-
9 Mar 2012 3:27 AM #1
Submitting a form
Submitting a form
Hello everyone.
I've copied this code into my appliation.
HTML Code:Ext.onReady(function() { Ext.create('Ext.form.Panel', { title: 'Simple Form', bodyPadding: 5, width: 350, // The form will submit an AJAX request to this URL when submitted url: 'save-form.php', // Fields will be arranged vertically, stretched to full width layout: 'anchor', defaults: { anchor: '100%' }, // The fields defaultType: 'textfield', items: [{ fieldLabel: 'First Name', name: 'first', allowBlank: false },{ fieldLabel: 'Last Name', name: 'last', allowBlank: false }], // Reset and Submit buttons buttons: [{ text: 'Reset', handler: function() { this.up('form').getForm().reset(); } }, { text: 'Submit', formBind: true, //only enabled once the form is valid disabled: true, handler: function() { var form = this.up('form').getForm(); if (form.isValid()) { form.submit({ waitMsg: 'Saving Data...', success: function(form, action) { Ext.Msg.alert('Success', action.result.msg); }, failure: function(form, action) { Ext.Msg.alert('Failed', action.result.msg); } }); } } }], renderTo: 'form-block' }); });
Then i've created the save-form.php like this:
And the test.txt file.PHP Code:<?
$first = $_POST['first'];$last = $_POST['last'];
$num = "test.txt";$var=fopen($num,"w"); fwrite($var, $first.' - '.$last);fclose($var);
?>
When i compile the form and click on Submit, appear a message box with the 'Please Wait' text and a blue slider, and it continues to slide indefinitely. Why this happens? Moreover the txt files remains blank.
Thanks for reply
EDIT: the extjs code is the same of Example Usage of Ext.form.Panel in the API. I couldn't copy well it here, sorry.
-
9 Mar 2012 4:24 AM #2
-
11 Mar 2012 9:25 AM #3
I have to re-open this thread for another question:
this is my code (i hope it will look better than above).
It work fine but when i press Submit it switch to the php page indicated in the url. So the success block is useless; i want to use something like json, if is possible, in order to ensure that the server do what he must do, and after sends a response to client that displays a message according to this response.Code:Ext.onReady(function() { Ext.create('Ext.form.Panel', { title: 'Simple Form', bodyPadding: 5, width: 350, // The form will submit an AJAX request to this URL when submitted url: 'save-form.php', // Fields will be arranged vertically, stretched to full width layout: 'anchor', defaults: { anchor: '100%' }, // The fields defaultType: 'textfield', items: [{ fieldLabel: 'First Name', name: 'first', id: 'first', allowBlank: false },{ fieldLabel: 'Last Name', name: 'last', id: 'last', allowBlank: false }], // Reset and Submit buttons buttons: [{ text: 'Reset', handler: function() { this.up('form').getForm().reset(); } }, { text: 'Submit', formBind: true, //only enabled once the form is valid disabled: true, handler: function() { var form = this.up('form').getForm(); if (form.isValid()) { form.standardSubmit = true; form.submit({ success: function(form, action) { Ext.Msg.alert('Success', action.result.msg); }, failure: function(form, action) { Ext.Msg.alert('Failed', action.result.msg); } }); } } }], renderTo: 'form-block' }); });
Is it possible?


Reply With Quote