FORM Submission Help , AJAX Support

Sumission of Two forms with one Submit Button

Page 1 of 1

4 Replies - 794 Views - Last Post: 07 August 2007 - 11:51 AM

#1 mukeshid  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 01-August 07

FORM Submission Help , AJAX Support

Post icon  Posted 03 August 2007 - 11:57 AM

Hello Big Programming Fellows,
I am in a bit of problem with submission of two forms..

The problem is like this..

I have two forms in my HTML page, say..

<form name=form1 method=post action=location1>
...
..
.
</form>

<form name=form2 method2 action=location2>
...
..
.</form2>


In my case, only form2 is visible to user. and i want code like this..

Whenever user press form2, the form1 should be posted in background, without user knowledge, and as per user form2 submission should go as normal..

Means, procedure like this.

form2 Submit button pressed
onsubmit even generated
form1 posted by AJAX in background
after successfull posting of form1 in background
function returns true to onsubmit event of form2
so form2 get posted normally.


In simple words, one submit posts two forms, and user don't even come to know that another form was posted in background.

Is This A Good Question/Topic? 0
  • +

Replies To: FORM Submission Help , AJAX Support

#2 serializer  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 110
  • Joined: 25-June 07

Re: FORM Submission Help , AJAX Support

Posted 03 August 2007 - 01:14 PM

Wouldn't it be better to just use <hidden> fields in form2, and dispense with form1 altogether?

What you're trying to do is very non-standard and prone to break. For instance, if form2 completes submission *before* form1 (which could randomly happen based on network traffic fluctuations for instance), then form1 submission could be cancelled mid-way as soon as the new page starts loading.

You could send form1 with Ajax, and when the request is complete, call form2.submit.

Since you're using Ajax already, it'd be better to submit both forms in the same manner to avoid confusion. Or, just combine them into one form as stated.

--serializer
Was This Post Helpful? 0
  • +
  • -

#3 mukeshid  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 01-August 07

Re: FORM Submission Help , AJAX Support

Posted 03 August 2007 - 01:16 PM

View Postserializer, on 3 Aug, 2007 - 01:14 PM, said:

Wouldn't it be better to just use <hidden> fields in form2, and dispense with form1 altogether?

What you're trying to do is very non-standard and prone to break. For instance, if form2 completes submission *before* form1 (which could randomly happen based on network traffic fluctuations for instance), then form1 submission could be cancelled mid-way as soon as the new page starts loading.

You could send form1 with Ajax, and when the request is complete, call form2.submit.

Since you're using Ajax already, it'd be better to submit both forms in the same manner to avoid confusion. Or, just combine them into one form as stated.

--serializer


Actually the MAJOR problem is that i don't know AJAX :rolleyes:
that's why i am asking for HELP..
Was This Post Helpful? 0
  • +
  • -

#4 ahmad_511  Icon User is offline

  • MSX
  • member icon

Reputation: 131
  • View blog
  • Posts: 722
  • Joined: 28-April 07

Re: FORM Submission Help , AJAX Support

Posted 06 August 2007 - 02:37 PM

Hi there.
So is this what you want to do ?
1- click on the submit button on form2
2 the hidden form1 will post (using AJAX) its fields; And this will return (true or false)
3- If Ajax returns true then the form2 will post normally.

If that's right here is an answer:

First if you don't know AJAX take a look at this AJAX snippet Then continue reading...

1- Change the type of the submit button on form2 to "button"
<input type="button" value="Send" name="B1">


2- On click event call a function (let's say it called "doit")
<input type="button" onclick="doit()" value="Send" name="B1">


3- Now let's do some scripting using the ajax snippet

Put AJAX snippet in the document header like this
<head>
<script language="javascript">
// Insert the snippet here
</script>
</heaed>



Or just link it to your document like this:

Copy ajax snippet to a text file then save it as ajax.js and upload it to your site
<head>
<script language="javascript" src="the url where you upload the ajax.js file"></script>
</head>



The function:
In the header write this
function doit(){
Ajax_Send("POST","the form1 action url","the variable string",resfunc)// this will post form1 variables then will call "resfunc" to submit the form2 normally
}

function resfunc(res){
If  (res==true)form2.submit()// this will post form2 only when posting fprm1 return true
}



And this is it

I hope that's what you want, If not; don't hesitate to reply
Was This Post Helpful? 0
  • +
  • -

#5 mukeshid  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 01-August 07

Re: FORM Submission Help , AJAX Support

Posted 07 August 2007 - 11:51 AM

Hey Bro!!
Thanks a lot for your reply.
I had already cracked my problem ;)
still, thanks a lot man

and by the way, i followed same approach as you told.
:)

View Postahmad_511, on 6 Aug, 2007 - 02:37 PM, said:

Hi there.
So is this what you want to do ?
1- click on the submit button on form2
2 the hidden form1 will post (using AJAX) its fields; And this will return (true or false)
3- If Ajax returns true then the form2 will post normally.

If that's right here is an answer:

First if you don't know AJAX take a look at this AJAX snippet Then continue reading...

1- Change the type of the submit button on form2 to "button"
<input type="button" value="Send" name="B1">


2- On click event call a function (let's say it called "doit")
<input type="button" onclick="doit()" value="Send" name="B1">


3- Now let's do some scripting using the ajax snippet

Put AJAX snippet in the document header like this
<head>
<script language="javascript">
// Insert the snippet here
</script>
</heaed>



Or just link it to your document like this:

Copy ajax snippet to a text file then save it as ajax.js and upload it to your site
<head>
<script language="javascript" src="the url where you upload the ajax.js file"></script>
</head>



The function:
In the header write this
function doit(){
Ajax_Send("POST","the form1 action url","the variable string",resfunc)// this will post form1 variables then will call "resfunc" to submit the form2 normally
}

function resfunc(res){
If  (res==true)form2.submit()// this will post form2 only when posting fprm1 return true
}



And this is it

I hope that's what you want, If not; don't hesitate to reply

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1