jQuery: The Write Less, Do More JavaScript Library

Sumbit Twice a form

View: New views
4 Messages — Rating Filter:   Alert me  

Sumbit Twice a form

by xomero :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


How can i submit a form twice, let say I want to save the form data on
my database and with the send the same form data to a different script
in an external host.

Re: Sumbit Twice a form

by David Morton-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I'd script the database host to send the data on to the second site, myself...

On Fri, Jul 4, 2008 at 6:18 PM, xomero <xomero@...> wrote:

How can i submit a form twice, let say I want to save the form data on
my database and with the send the same form data to a different script
in an external host.



--
David Morton
mortonda@... - bulk address
mortonda@... - direct to my server

Re: Sumbit Twice a form

by Mahbub :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


There's actually no way of submitting a form twice in two action urls
in normal browser's capability. What you can do is that serialize all
your variables into string using serialize() and use AJAX to submit
into two locations one after another. like this

<form action="" id="pform" onsubmit="return submit_my_form();">
<input type="text" name="input1">
<input type="text" name="input2">
</form>
<script language="javascript">

function submit_my_form(){
   $.ajax({
     url : "url1.php",
     type : "post",
     data : $("#pform").serialize(),
     success : function(e){
      // so form is submitted successfully !!
     }
   });

   $.ajax({
     url : "url2.php",
     type : "post",
     data : $("#pform").serialize(),
     success : function(e){
      // so form is submitted successfully !!
     }
   });
   return false;
}

</script>

Hope this helps!!

On Jul 5, 5:18 am, xomero <xom...@...> wrote:
> How can i submit a form twice, let say I want to save the form data on
> my database and with the send the same form data to a different script
> in an external host.

Re: Sumbit Twice a form

by Alexandre Plennevaux :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On Mon, Jul 7, 2008 at 9:02 AM, Mahbub <pappu687@...> wrote:

>
> There's actually no way of submitting a form twice in two action urls
> in normal browser's capability. What you can do is that serialize all
> your variables into string using serialize() and use AJAX to submit
> into two locations one after another. like this
>
> <form action="" id="pform" onsubmit="return submit_my_form();">
> <input type="text" name="input1">
> <input type="text" name="input2">
> </form>
> <script language="javascript">
>
> function submit_my_form(){
>   $.ajax({
>     url : "url1.php",
>     type : "post",
>     data : $("#pform").serialize(),
>     success : function(e){
>      // so form is submitted successfully !!
>     }
>   });
>
>   $.ajax({
>     url : "url2.php",
>     type : "post",
>     data : $("#pform").serialize(),
>     success : function(e){
>      // so form is submitted successfully !!
>     }
>   });
>   return false;
> }
>
> </script>
>
> Hope this helps!!
>
> On Jul 5, 5:18 am, xomero <xom...@...> wrote:
>> How can i submit a form twice, let say I want to save the form data on
>> my database and with the send the same form data to a different script
>> in an external host.
>


i would handle that on the serverside of life, not the clientside.
basically, your serverside script processes the form, saves it in a
database, then if all correct, call the external form, via GET (that
is, as query variables).

--
Alexandre Plennevaux
LAb[au]

http://www.lab-au.com