Page 1 of 1
As page loads, perform an action
Posted: Tue Apr 10, 2012 4:28 pm
by Jamesiv22
I have a form with shopping cart items that when submitted, goes to
phpcart-m.php
phpcart-m.php calculates the shopping cart items and sends to
phpcart.php?action=view which displays all the items on a page called
display.php
The URL when
display.php loads is
http://mydomain/phpcart.php?action=view
As
display.php loads, I need it to perform a different action: instead of
phpcart.php?action=view, I need it to perform
phpcart.php?action=confirm
I'm thinking at the top of
display.php, I need something like this:
<?php
execute (phpcart.php?action=confirm);
?>
I tried changing the header but got this error "Warning: Cannot modify header information - headers already sent by...."
phpcart-m.php and
phpcart.php are Zend-encoded, so I don't have access to that code.
Is this possible?
Re: As page loads, perform an action
Posted: Tue Apr 10, 2012 4:48 pm
by requinix
"As it loads" is kinda vague. How is it supposed to do the confirm action and then switch to the view action? Doesn't the confirm page show some kind of HTML? You can't just get rid of it - executing it means the user will see that page.
Re: As page loads, perform an action
Posted: Tue Apr 10, 2012 4:59 pm
by Jamesiv22
It's a little hard to explain, but I'll try:
The shopping cart is a "template" system - I can tweak the template files (pages that display the information), but do not have access to the code that drives it all.
All the cart items first get sent to phpcart-m.php where it calculates a total and subtotal and displays the items with a URL of
http://www.mydomain.com/phpcart.php?action=view
The data must go to phpcart-m.php first (to calculate totals), but after ?action=view I want it to execute ?action=confirm.
So I'm hoping that as display.php (a template file I can edit) "loads" (begins to display in the browser) - at the top of the html I can put some php that will execute ?action=confirm. ?action=view has already been performed... I just need to figure out how to execute ?action=confirm
Does that help? I'll set it up on my website so you can have a look if you like.
Thanks for replying.
James
Re: As page loads, perform an action
Posted: Tue Apr 10, 2012 5:25 pm
by Jamesiv22
I set it up here so you can see how it behaves, if you like:
http://www.iampeth.com/2012_registration_formTEST.php
1. select your items > click submit
2. it displays all the cart items > click "Checkout"
3. You enter name, address, phone, etc > click "Verify your information". That button performs ?action=confirm
I'm trying to skip that page where you enter name, address, phone, etc (because I captured that info earlier) and go straight to the confirmation page.
Re: As page loads, perform an action
Posted: Tue Apr 10, 2012 5:30 pm
by requinix
If you simply need to execute the ?action=confirm code without caring about the output then you can
Code: Select all
// function so (hopefully) what phpcart.php does won't screw up anything
function confirm() {
$_GET["action"] = "confirm"; // new value to trick phpcart.php
ob_start(); // capture output
include "phpcart.php";
ob_end_clean(); // throw it away
$_GET["action"] = "view"; // original value
}
confirm();
but I'm not sure where you would put that. In display.php? But then wouldn't it execute for every single page load? That's very bad. And in your first post you said "instead" but now you say "after"? I don't know, but odds are that code above is close to what you need to use.
And now it seems like you really want to skip the ?action=checkout page. That's the one that gathers information that you say you already have...
Re: As page loads, perform an action
Posted: Wed Apr 11, 2012 7:39 am
by Jamesiv22
Hi requinix,
Couldn't make it work

It didn't like the include for some reason - error was something like "Can't do it cause it's already been declared" or some such.
That's Ok. I reversed my approach, and set it up to gather shopping cart items first > send to phpcart-m.php like normal (and perform ?action=view) > then once inside the shopping cart gather the additional information I need (a bunch of custom fields I didn't think the shopping cart would allow me to create). Works good.
Thank you very much for replying. I appreciate it.
James