SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Addict frankdux's Avatar
    Join Date
    Apr 2004
    Location
    Ashland, North Carolina
    Posts
    267
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Submit form data to 2 different places?

    I need to post form data get to 2 different locations. 1 is a file on the same website and the other is an external website. Any suggestions on options to accomplish this?

    Note: I originally posted to the Classic ASP forum at http://www.sitepoint.com/forums/showthread.php?t=551247, but I think it's more of a Javascript solution.

  2. #2
    SitePoint Zealot
    Join Date
    Oct 2007
    Posts
    148
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you could set up two extra forms (form B and C) with the same vars as first one but hidden. when submitting form A, call a js function like this:

    <form name="formB" action="localscript.cgi">
    ..
    ..

    <form name="formC" action="http://server/cgi-bin/other.cgi">

    function sendform() {

    document.forms.formB.something.value = document.forms.formA.something.value;
    ...
    ...

    document.forms.formC.something.value = document.forms.formA.something.value;
    ...
    ...

    document.forms.formB.submit();
    document.forms.formC.submit();
    }

  3. #3
    SitePoint Addict frankdux's Avatar
    Join Date
    Apr 2004
    Location
    Ashland, North Carolina
    Posts
    267
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried the code below, but it didn't work. Any ideeas?

    Code:
    <script type="text/javascript">
    function sendform() {
    
    document.forms.formB.Name.value = document.forms.formA.Name.value;
    document.forms.formB.Town.value = document.forms.formA.Town.value;
    
    document.forms.formC.Name.value = document.forms.formA.Name.value;
    document.forms.formB.Town.value = document.forms.formA.Town.value;
    
    
    document.forms.formB.submit();
    document.forms.formC.submit();
    }
    </script>
    
    <form method="post" name="formA" onSubmit="sendform();">
            <dl>
                <dt><label for="Name">Name: *</label></dt>
                <dd><input type="text" name="Name" /></dd>
                <dt><label for="Town">Town:</label></dt>
                <dd><input type="text" name="Town" size="35" /></dd>
                
                <input type="submit" class="submit" value="submit" />
            </dl>
        </form>
    
    <form name="formB" action="mailer.php" style="display: none;">
        </form>
    
        <form name="formC" action="mailer2.php" style="display: none;">
        </form>
    Quote Originally Posted by bluestartech View Post
    you could set up two extra forms (form B and C) with the same vars as first one but hidden. when submitting form A, call a js function like this:

    <form name="formB" action="localscript.cgi">
    ..
    ..

    <form name="formC" action="http://server/cgi-bin/other.cgi">

    function sendform() {

    document.forms.formB.something.value = document.forms.formA.something.value;
    ...
    ...

    document.forms.formC.something.value = document.forms.formA.something.value;
    ...
    ...

    document.forms.formB.submit();
    document.forms.formC.submit();
    }

  4. #4
    SitePoint Zealot
    Join Date
    Oct 2007
    Posts
    148
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you need to add the hidden fields to formB and C:

    i.e.
    <form name="formB" action"mailer.cgi">
    <input type="hidden" name="Town" value="">
    ...
    ...
    etc
    </form>

  5. #5
    SitePoint Addict frankdux's Avatar
    Join Date
    Apr 2004
    Location
    Ashland, North Carolina
    Posts
    267
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I added the hidden input fields as shown below, but it still does not work.

    HTML Code:
    <form name="formB" action="mailer.php" style="display: none;">
        <input type="hidden" name="Name" value="">
        <input type="hidden" name="Town" value="">
        
        </form>
    
        <form name="formC" action="mailer2.php" style="display: none;">
        <input type="hidden" name="Name" value="">
        <input type="hidden" name="Town" value="">
        </form>

  6. #6
    SitePoint Addict
    Join Date
    Dec 2007
    Posts
    207
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm... Why do you want to send the data twice? I doubt sending it twice is the best solution.

    Also, that code won't work, you'd have to do something like an iframe and submit one form first, then the other.

  7. #7
    SitePoint Addict frankdux's Avatar
    Join Date
    Apr 2004
    Location
    Ashland, North Carolina
    Posts
    267
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Of course I know that it's not the greatest thing to be placing the same data into 2 different places. That what the client wants though, so that's what I have to do.

    How would I do it with an iframe?

    Quote Originally Posted by M-M-J View Post
    Hmm... Why do you want to send the data twice? I doubt sending it twice is the best solution.

    Also, that code won't work, you'd have to do something like an iframe and submit one form first, then the other.

  8. #8
    SitePoint Zealot
    Join Date
    Oct 2007
    Posts
    148
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try an onclick instead of onsubmit, also good point about the iframe's, that may be a good idea...there needs to be somewhere to send the second form to...just rem to use target="newframe" in formB/C tag...

  9. #9
    SitePoint Addict
    Join Date
    Dec 2007
    Posts
    207
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by frankdux View Post
    Of course I know that it's not the greatest thing to be placing the same data into 2 different places. That what the client wants though, so that's what I have to do.
    What I'm trying to say is that you're looking at the problem the wrong way.

    Tell us exactly what it is you need to accomplish and we should be able to figure out something better.

  10. #10
    SitePoint Guru
    Join Date
    Mar 2006
    Posts
    701
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Did you thing a "ajax solution"?
    You make a javascript function and with that you submit the form at different files.


Bookmarks

Posting Permissions

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