View Full Version : Problem with form submission

14 Oct 2010, 6:57 AM

I was trying to create a simple login form, but there was a problem with the submission. It didn't work when I clicked the login button.

Here are some of my codes about submission:

var doaction=function(){
var userName = form.getValues().name;

if(userName == "" || userName == null){
Ext.Msg.alert('Caution', 'Please Input Your Username!',
} else {
waitMsg : {message:'Submitting', cls : 'demos-loading'}

I am a novice in sencha and extjs, I am not sure about how to submit here.
How to submit a form?
Can anyone give me some suggestions? Thanks in advance!

14 Oct 2010, 3:03 PM
I don't see particularly wrong with that, what do you mean by "doesn't work"? If you look in the resources tab do you see it fires off a request?

14 Oct 2010, 9:28 PM
It didn't transfer to the URL '/project/loginAction.do' as I designed.
I tried to debug that and found the 'loginAcion' did not process. I guess it didn't fire off a request.

I added the following code to the submit method :

success : function(response) {},
failure : function() {
//failed to request
Ext.Msg.alert('Information', 'Failed to connection!');

It alert 'Failed to connection' ...

15 Oct 2010, 12:22 AM
Hi, your loginAction.do must return a json formatted response with success: true or false, look at the sencha touch form example and also test the loginAction.do via direct url by appending the required parameter to the url itself.

15 Oct 2010, 6:11 AM
@steve1964 - do you mean the Forms example in the Kitchen Sink examples? I am having a similar problem and I think it has to do with properly formatting the JSON response. I just can't seem to find an example of what a proper JSON response looks like. My callback never gets fired.

15 Oct 2010, 6:25 AM
Not in Kitchen Sink examples, there is a form demo in the download package you can run on localhost, or just edit the php file in the same folder of the example to see how the json is formatted to return true or false to Sencha Forms...

15 Oct 2010, 6:28 AM
This is the php code of the example (postUser.php):

$pw = $_REQUEST['password'];
header('Content-Type: application/json');
if($pw != ''){
echo '{"success":true, "msg":'.json_encode('This User is authorized').'}';
echo '{"success":false, "msg":'.
json_encode('This User is NOT authorized').
', "errors" : { "password" :'.json_encode('Password is required').
', "pwd" :'.json_encode($pw).'}';

15 Oct 2010, 6:49 AM
Thanks steve, I see the example now. Unfortunately I don't know PHP so I'm trying to figure out if ultimately this is returning a string or a JSONObject or what. I'm making a JSONP request and my Java servlet is returning a string that looks like this:

{"results":[{"value":"T1","label":"Test1"},{"value":"T2","label":"Test2"},{"value":"T3","label":"Test3"},{"value":"T4","label":"Test4"}]}I'm just confused if the request is expecting a string back or something else. I'm trying to re-use an existing java application and there doesn't seem to be many examples of Java code returning from a a JSON request. Most examples show PHP.

15 Oct 2010, 6:52 AM
Did you try to debugging your page with Safari developers tools? If so, does your script correctly make the request to you php page? If the request is correctly done, the problem is the json data you return to the client. Remeber that the json properties should be double quoted

echo "{\"success\": true, \"msg\": \"This User is authorized\"}";

15 Oct 2010, 7:08 AM
Andrea the php code is part of the Sencha Touch Examples. and i use similar code in my webapp and it works, the json_encode php function adds the double quote.

For dac0nvu, you cannot return a json to a Sencha Form in this way, you must return true or success to handle the listeners of the form

15 Oct 2010, 7:11 AM
Json success:

{"success":true, "msg":"This User is authorized"}

Json failure:

{"success":false, "msg":"This User is NOT authorized", "errors" : { "password" :"Password is required"}, "pwd" :"test02"}