Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

form action question

Status
Not open for further replies.

judi

Programmer
Jan 13, 2001
35
US
I want to be able to take a different action with one submit button depending on circumstances. So I'm trying to use the following statement.

If ($ErrFlag) {
echo "<BR>this should be customer";
echo "<form NAME=\"errform\" ACTION=\"customer.php\">";
}
else {
echo "<BR>this should be checkout";
echo "<form NAME=\"goodform\" ACTION=\"checkout.php\">";
}


My problem is this. If there is no error, it definitely gets to the else because it echo the "this should be checkout" statement. It doesn't go to checkout.php. It stays in Customer. However, if I click submit again without changing anything, it goes to checkout.

I had a Switch program I was using but it did the same thing. It wouldn't work the first time I hit submit, but it hit the second time.

What am I doing wrong?

Thanks in advance.
 
Judi,

From your explaination it sounds as though you have the if statement in the customer.php file. Is this correct?

Could you provide a bit more information on where you get the $ErrFlag variable content from?

Toby Heywood
 
Your PHP script generates output to the client's browser. Printing out HTML with a form tag that points to destination X will not redirect the browser, it will, just as you describe, send the form data upon the next submit to the specified script.

There is the header directive which redirects the user's browser. A better solution for you is to just include the code for the error page. You variables will be there and you can generate the desired output.
 
To Toby, yes, the if statement is in customer.php.

DRJ478: I am including the error checking code in the customer.php. It's really calling itself.

But then, if there are no errors, it should go to checkout.php and it doesn't til I hit submit the second time.

I tried using Include checkout.php with a break. This works perfectly but it gives me a fatal error message on the checkout screen. If not for the message, everything else on the screen is exactly what I want.
 
Ok. This is a basic code layout question.

When you say: It should go to the checkout.php if there are no errors - we need more info.

Do you use session variables to keep the submitted values persistent?
What does checkout.php do and from where does it draw the values to work?


 
I've tried this several ways with the same result. One of the ways I tried doing this was by using a switch program that works fine with my other forms. But in customer if I have the action go to the switch program when the user hits the delay button, something very strange happens.

I do use a session variable for the errflag and if I explicitly define a session var to true, the value is carried over to the switch program. If I put it within an if statement, it doesn't. I have a display within the if statement, so I know it's getting to the right place. I also display the errflag and the value is correct.

However, in my switch program session errflag value isn't correct the first time I hit submit. But if I hit submit again with the same criteria, it puts the correct value into errflag.

That's similar to what happens if I dont use a switch program and use the If statement to generate a different form with a different action like my code shows above, I also have to hit the submit button twice to get the correct action.

Using an include within customer.php works perfectly but for the fatal error message.

I can't think of another way to do this. Thanks for your patience.
 
To validate your observations:
just after the session_start() print out all session variables, so we can see if they really exist the first time or not:
[code[
echo "<pre>";
print_r($_SESSION);
echo("</pre>");[/code]

 
They do exist. I'm displaying echo
$_SESSION["CheckCust"]
$_SESSION["$error_flag"]

They have no value, obviously, the first time. When you hit submit in the customer form, those vars have a value but the session vars in the switch program dont until you hit submit yet again.
 
I'm so embarrassed. I fixed it myself. It was a misplaced bracket. I'm so sorry I bothered you with something so stupid. You know how you can look at code for hours and only when you seek outside help, you find the problem.

Thanks for your help.
judi with egg on my face
 
It happens to all of us Judi, if we'd all take it that seriously, there won't be enough eggs to go around!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top