PDA

View Full Version : Form vals to server via AJAX



onlinesaratoga
22 Apr 2007, 7:32 PM
This isn't working:



loginForm.addButton('Log In', function(){
loginForm.load({url:'load-form.php',params:{loginForm.getValues()}});
});


Am I even on the right track for how to do this, or is there another way?

steven
22 Apr 2007, 9:28 PM
This is what I have done to send data from the client to the server


this.form = new Ext.form.Form({url: 'AddSerial.aspx'});
... Create text fields etc ...

This is the button click function
this.addSerial = function() {
this.form.submit({waitMsg: 'Please wait...'});
}


All the text fields are sent in the submit. You can then do validation on the server and send a response that says whether the submit was valid. I think there is documentation or a thread on it somewhere but as an example, if I have a failure I might send this:

{ success: false, errors: {email: 'The email address is already in use'} }

and for success

{ success: true }

onlinesaratoga
23 Apr 2007, 4:32 AM
Jack (and the Ext team),

most of the posts I found in searching for form submission were like steven's above (which I appreciate Steven!) - "I think you can do it this way." "You might be able to do it that way."

I know forms are relatively new, but a good solid example for best practices for validating form data, sending via AJAX and capturing the server response would likely be helpful to many of us.

Thank you all for the continued extraordinary work!

Update:
Found a couple of good threads. Won't be able to test them out for myself until much later today, but thought it might help others:

http://extjs.com/forum/showthread.php?t=4741
http://extjs.com/forum/showthread.php?t=4403

23 Apr 2007, 8:21 AM
^^^ thanks for the posts. been wrangling w/ this myself. Things are so much easier w/ examples to rip from :)