homepage Welcome to WebmasterWorld Guest from 54.227.12.4
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Form submission scripting - architecture advice needed
Need advice on performing multiple actions with each submission
jdbnd




msg:3829535
 2:57 pm on Jan 19, 2009 (gmt 0)

I have a pretty simple HTML form, and each time the form is submitted I need to take the following actions (and I'm wondering what the best approach is - a single Javascript function, Javascript + PHP, etc.).

1) POST the form field values to an external URL (for an affiliate program)

2) grab some XML data returned by the external URL (to tell me whether the form was accepted, give me a unique ID for it, etc.)

3) log that XML data PLUS the original form field values in a local MySQL database

4) send the user to a thank-you page on my own site

My issue is how to make the HTML form action, the Javascript POST command, and everything else all play nicely together given that (as I understand it) you can only submit a form once per page so I can't just do sequential POST commands with Javascript (one for the external URL, one to a local PHP script to insert data into the MySQL database).

Please help point me in the right direction if you can.....

Thanks,
Joe

 

korkus2000




msg:3829547
 3:16 pm on Jan 19, 2009 (gmt 0)

Why are you not just using PHP and HTML for this? Just post to a PHP page and do your submitting and receiving there. Then just redirect to a thank you page. I am not sure what you are gaining from using javascript.

jdbnd




msg:3829565
 3:28 pm on Jan 19, 2009 (gmt 0)

Would you just use the header function in PHP to post to the external URL?

Thanks,
Joe

korkus2000




msg:3829599
 4:07 pm on Jan 19, 2009 (gmt 0)

To me the javascript adds a layer of uncertainty to the software. People may not have javascript working. Mobile device or just having it off in their browser. Letting the server handle all of that with basic HTML post would mean that you have less variables on getting the sale.

Personally I haven't used PHP for a while so the actual details I don't know. From what you listed though I would have a PHP processing script that the page submits to, could be the same page. Then do all the processing there and redirect to an error page/form page with error message, or send to thank you page.

Looking at some search results the header does sound like it would work. Do you have access to curl? I would try curl first if your server has the library.

jdbnd




msg:3829703
 6:24 pm on Jan 19, 2009 (gmt 0)

I've refined my issue a bit... trying to figure out if I have access to curl.

I can use PHP Header to send a GET, but the issue is that it then visibly displays the server response. I'm trying to find a way of using PHP to send the form data using GET or POST that happens entirely behind the scenes, so all the user sees is the thank-you page on my site.

Then I need to use PHP to parse the XML response from the server, but first things first.....

Joe

jdbnd




msg:3829751
 7:21 pm on Jan 19, 2009 (gmt 0)

Got cURL to work so I can POST the form data, now I just need to figure out how to grab the XML response and parse it.

Joe

jdbnd




msg:3829928
 11:19 pm on Jan 19, 2009 (gmt 0)

Solved it... happy to help anyone who's having the same issue.

Joe

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved