how can I submit a form multiple times - without redirecting

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jrswastaken
Forum Newbie
Posts: 3
Joined: Fri Sep 08, 2006 1:52 am

how can I submit a form multiple times - without redirecting

Post 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
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post by alex.barylski »

I would think it's possible using AJAX...

Look into AJAX ;)
jrswastaken
Forum Newbie
Posts: 3
Joined: Fri Sep 08, 2006 1:52 am

Post 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;
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post 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.
jrswastaken
Forum Newbie
Posts: 3
Joined: Fri Sep 08, 2006 1:52 am

Post 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
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post 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>
Post Reply