PDA

View Full Version : How can I submit a form using normal http post method?



allenyoung
21 May 2007, 3:51 AM
Hi all,

I'm quite new to ExtJS and am trying to use it in my project. I've followed some tutorials to create forms. But all the tutorials just use Ext.form.Form's submit method to submit the form through xmlhttprequest. What if I don't want to submit the form using ajax but a normal http way? Any idea about this? Thanks a lot.

jsakalos
21 May 2007, 4:03 AM
Ext.fly('form-id').dom.submit()

But why would you do that? ;)

allenyoung
21 May 2007, 4:16 AM
Ext.fly('form-id').dom.submit()

How can I specify my form's id. So far as I now, ExtJS will generated the form dynamically with some generated id.


But why would you do that? ;)

Well, first, I think submit the form without using ajax is what I need according to my requirements. Second, to tell you the truth, I got a json syntax error while submit the form using ajax because my server side code returned the whole html back.

I'm using RoR 1.2.3 with ExtJS. I've checked out the accept type of a ExtJS ajax request, which is basically "text/html, text/xml" and expect a json format response. But according to the REST inplementation of rails, these kinds of ajax requests' accept type should be "javascript". Of course, I can get ride of this and just return some json text, but this is not what I supposed to do anyway.

Why form.submit() expects a json response text while doesn't set the accept type to "javascript"? Any particular reasons?

jsakalos
21 May 2007, 4:35 AM
How can I specify my form's id.You can while creating form or in html markup <form id='form-id' ....>


Well, first, I think submit the form without using ajax is what I need according to my requirements.Good idea! Go for it. You can find plenty of advices/solutions on the matter in this forum.


I'm using RoR 1.2.3 with ExtJS.I don't use it so I don't know. Somebody else?

allenyoung
21 May 2007, 4:57 AM
You can while creating form or in html markup <form id='form-id' ....>


I don't quite get it. Say I have the following code:


<div style="width:300px;">
<div class="x-box-tl"><div class="x-box-tr"><div class="x-box-tc"></div></div></div>
<div class="x-box-ml"><div class="x-box-mr"><div class="x-box-mc">
<h3 style="margin-bottom:5px;">Simple Form</h3>
<div id="form-ct">

</div>
</div></div></div>
<div class="x-box-bl"><div class="x-box-br"><div class="x-box-bc"></div></div></div>
</div>

and


Ext.onReady(function(){
Ext.QuickTips.init();
Ext.form.Field.prototype.msgTarget = 'side';
var simple = new Ext.form.Form({
labelWidth: 75,
url:'save-form.php',
});
simple.add(
new Ext.form.TextField({
fieldLabel: 'First Name',
name: 'first',
width:175,
allowBlank:false
}),

new Ext.form.TextField({
fieldLabel: 'Last Name',
name: 'last',
width:175
}),

new Ext.form.TextField({
fieldLabel: 'Company',
name: 'company',
width:175
}),

new Ext.form.TextField({
fieldLabel: 'Email',
name: 'email',
vtype:'email',
width:175
})
);

simple.addButton('Save', function(){
simple.load({url:'load-form.php'});
});
simple.addButton('Cancel');

simple.render('form-ct');
});

Then it will generate a form in <div id="form-ct"> with a generated form id. How can I set my own id?

jsakalos
21 May 2007, 5:48 AM
var simple = new Ext.form.Form({
labelWidth: 75,
url:'save-form.php',
id: 'form-id'
});



BTW, you have extra comma in your code. Your app won't work in IE.

tpattison
21 May 2007, 6:12 AM
Search is your friend. ;)

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