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!
I have code that tells the user a bunch of stuff, then if certain conditions are met I want the page to create a session and move onto another page (which is page 2 of a signup / registration script, for those interested ).
I have to output text to let the user know certain things and I have to be able to redirect if a condition is met.
If I understand correctly then you're going to have to use some javascript or similarly capable client side language. If you describe your situation a little bit more I can probably offer more insight into solutions.
Basically, the code is a page that accepts form data.
It then goes through the form data, does checks to see if username is correct, if the email address has been taken/is correct, if their birthdate makes them old enough to use the forums etc. When that's done it then shows them their input and or any errors.
If there's errors it re-directs them back to the input page they came from (with highlited errors) or if it was error free it will re-direct them forward to page 2 of registration.
It seems you're most likely correct, I'll have a hunt around for some java scripty stuff (damn).
<?php
if ($_POSTї'doSubmit']) {
// The form has been submitted, from here we can proceed to validate individual fields:
if ($_POSTї'requiredField1')) {
// requiredField1 has a value
// send user to the next form:
header("e;Location: form2.php"e;);
} else {
// requiredField1 has no value
// here you can set some error variable that can be used later to tell the user that she didn't complete the form
}
}
?>
<form>
<input type="e;text"e; name="e;requiredField1"e; />
<input type="e;submit"e; name="e;doSubmit"e; />
</form>
As a note.
You cannot send headers after you have echoed data, furthermore, I really really don't see why you would ever want that with redirect, as doing a redirect would never show what has been echoed, which would just waste bandwidth.
Don't output things in the same script you're doing checks in. Do the checks and if an error is hit, redirect somewhere else.
I always write scripts dedicated to validation, login, logout etc etc... these scripts don't output anything at all... they just process data... use other scripts which can be controlled via the above to handle data output.
Note: Don't rely on javaScript if your website will not function correctly without it neither.
What I'll aim to do is seperate error checking / processing from output (it's almost like that already) and I think I'll use sessions to do it (as I can't stand doing a tonne of $_GET's ).
Most of my scripts written for the site actually are seperate dedicated login/logout etc scripts, I guess this time I tried to get too tricky in one script, and for no reason at all. That will be my next mission then Get this particular script more modular in its design and execution.
Thanks again everyone. I'll begin with that code snippit and go from there.