Page 1 of 1
how can I submit a form multiple times - without redirecting
Posted: Fri Sep 08, 2006 1:57 am
by jrswastaken
Hi All,
I have a shoppping basket like page and I need to submit it to a processing script one item at a time.
How can I submit a form without it redirecting - prefferably with a wait of half a second between each item?
I'm able to use php and javascript
Thanks in advance - James
Posted: Fri Sep 08, 2006 2:01 am
by alex.barylski
I would think it's possible using AJAX...
Look into AJAX

Posted: Fri Sep 08, 2006 3:53 am
by jrswastaken
Thanks for your reply
I've looked into ajax and can see how to do it on the client side using javascript but I'd like php to do it as there is some sensitive data I'd preffer to not have transmitted to the client.
Here is some of the java script method I've found - I've been assuming there is something similar in php to allow requests to be created and sent but can't find anything.
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
try
{
xmlhttp = new XMLHttpRequest();
} catch (e) {
xmlhttp = false;
}
}
return xmlhttp;
Posted: Fri Sep 08, 2006 4:35 am
by patrikG
no need to "re-submit" a form, just have the php-script (or class method) call another script (or class method) which then does the second step of submittal (i.e. data processing) and pass the $_POST variable as a parameter.
Posted: Sat Sep 09, 2006 10:27 pm
by jrswastaken
Hi Thanks for your help so far
Maybe i'm not being clear - or just stupid
but how do I make the php script I have access to do multiple form submissions? My shopping basket page will submit a list of items to my processing script which needs to individually submit these items to a checkout script which I don't have any access to or control over.
In javascript I can do document.my_form.submit() but then I get redirected by the script which handles this form - I need to have this not happen (until the last item) so that my processing script can submit all the items to this checkout script.
How do I make a function in PHP that I can call with the form data (required by the checkout) such that it submits and doesn't redirect me - a function that doesnt return
Posted: Sun Sep 10, 2006 3:26 am
by patrikG
jrswastaken wrote:but how do I make the php script I have access to do multiple form submissions? My shopping basket page will submit a list of items to my processing script which needs to individually submit these items to a checkout script which I don't have any access to or control over.
You don't "submit" with PHP (serverside). That's what you do with HTML (clientside). In PHP you handle data and you can send it to another place (script, database, session, server, whatever) and you can do so repeatedly with a loop (e.g.
for ,
foreach(),
while ,
do-while ).
jrswastaken wrote:In javascript I can do document.my_form.submit() but then I get redirected by the script which handles this form - I need to have this not happen (until the last item) so that my processing script can submit all the items to this checkout script.
How do I make a function in PHP that I can call with the form data (required by the checkout) such that it submits and doesn't redirect me - a function that doesnt return
There are many solutions, the easiest one would probably be to have the form submit to itself a la
Code: Select all
<form action="<?PHP echo $_SERVER['PHP_SELF']?>">
... html stuff
</form>