www.webdeveloper.com
Results 1 to 8 of 8

Thread: Two actions in one form

  1. #1
    Join Date
    Dec 2005
    Posts
    1

    Two actions in one form

    Hi,

    Please help. I confess I'm no Java expert.
    I have a form. When the user clicks submit I would like form to be sent to two different cgi scripts.

    Please help and don't forget to make it simple.

    Many thanks
    Lyle

  2. #2
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    You may use trick. Try this:

    First add on your page two "hidden" iframes where you may submit.
    PHP Code:
    <div style="visibility:hidden">
    <
    iframe name="ifr1" width="20" height="20"></iframe>
    <
    iframe name="ifr2" width="20" height="20"></iframe>
    </
    div
    Now you can build a function
    PHP Code:
    <script type="text/javascript">
    function 
    submitTwice(f){
    f.action 'first.php';
    f.target='ifr1';
    f.submit();
    f.action 'second.php';
    f.target='ifr2';
    f.submit();
    }
    </script> 
    and the form:
    PHP Code:
    <form method="post">
    ....
    <
    input type="button" value="Send" onclick="submitTwice(this.form)">
    </
    form

  3. #3
    Join Date
    May 2007
    Posts
    8
    This is an AWESOME script. I know nothing about Javascript and was still able to use it. I have a question though. Is it possible to add a verification script to this? The script I need to use requires the form to have a name and I can't seem to figure out where to put it. Any ideas?

  4. #4
    Join Date
    Mar 2008
    Posts
    1
    thanks mate. this is realy working.

  5. #5
    Join Date
    Mar 2004
    Location
    Texas
    Posts
    5

    Firefox problems

    Has anyone encountered any problems w/ this scipt working in Firefox? It works wonderfully for me in IE; but, does not submit any data via FF.

  6. #6
    Join Date
    Jul 2008
    Posts
    2
    i've tried this ....

    link 1 works when "f.target='ifr*';" is included and link 2 works when it is deleted. They don't both work together.

    anyone?
    Last edited by tifotifo; 07-31-2008 at 07:40 AM.

  7. #7
    Join Date
    Apr 2010
    Posts
    1
    That really worked and yes it worked in Firefox.

    Now, after submitting i had a thankyou page which comes. Here after putting the first code in the thankyou page that is this:
    "<div style="visibility:hidden">
    <iframe name="ifr1" width="20" height="20"></iframe>
    <iframe name="ifr2" width="20" height="20"></iframe>
    </div>"

    As my thankyou page was itself integrated in my action script when i submitted i got two thank you pages in new window which i dont want, infact i want the thankyou page to be opened in the same window, so i simply deleted f.target from the javascript, so now

    Instead of this:
    <script type="text/javascript">
    function submitTwice(f){
    f.action = 'first.php';
    f.target='ifr1';
    f.submit();
    f.action = 'second.php';
    f.target='ifr2';
    f.submit();
    }
    </script>

    i kept in the header of the contact for this:
    <script type="text/javascript">
    function submitTwice(f){
    f.action = 'first.php';
    f.submit();
    f.action = 'second.php';
    f.submit();
    }
    </script>

    Thats it, But thanks Kor after all i got what i needed becaz of you.

  8. #8
    Join Date
    Jun 2007
    Posts
    667
    Quote Originally Posted by tifotifo View Post
    i've tried this ....

    link 1 works when "f.target='ifr*';" is included and link 2 works when it is deleted. They don't both work together.

    anyone?
    Some browsers may have a problem with queueing the data from two forms, so it's not entirely surprising that it failed and I don't think it could be considered reliable. If a JavaScript-dependent solution is acceptable, an AJAX routine would be far more dependable, but the best solution has to be a server-side forwarding script.
    Y_U U_G_A_E_U_ B_S_A_D_

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles