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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Redirect

Status
Not open for further replies.

Rhiannon

Technical User
Feb 8, 2002
55
US
Okay, I'm not sure you can do this or not.

I have a seven page membership application that is working fine... BUT... what is happening people are skipping pages that have required fields on them.

What I want to do is if they go directly to instead of

I want to redirect them back to the first page. I know about the redirect header but if I use that then when they hit "submit" on page 2 the header will take them back to page 1.

Can any on you php wizards out there help me with this? Please be gentle... I'm VERY new with php.

Cheers,
Rhiannon
 
Hello again, glad to hear your making progress.

What I'd suggest is sticking with the redirect header you have... but put it within a conditional.

Remind me, are you using sessions?

If so you could toss it in a session variable... if not, I know you already have a host of hidden variables, so add one more... let's call it page_num

So then it'll go like this
Code:
<?php
/* Script for second page */
if ($_POST[&quot;page_num&quot;] == 1) {
 ...
 all the normal stuff
 ...
} else {
  redirect to page 1
}
?>

<?php
/* Script for third page */
if ($_POST[&quot;page_num] == 2) {
 ...
 all the normal stuff
 ...
} else {
 redirect to page 1
}
?>
-Rob
 
Hi Rob,

Okay, bare with me... it's Friday and I'm exhausted. :)

I take it this script goes at the very top of the page, correct? I'm confused about what &quot;all the normal stuff&quot; is and do I put the header in where you have &quot;redirect to page1&quot;?

I'm lost. :)

Rhiannon
 
Yes, goes at the very top of the page...

...
all the normal stuff
...

Would get replaced with all the code you have there already... so basically if you removed the <? ?> tags from your current page, you could just surround it all with that conditional statement.

And yes, the header goes where I have redirect to page 1


-Rob
 
Okay. I think I see where you're going.

Basically I would have:


<?php
/* Script for second page */
if ($_POST[&quot;page_num&quot;] == 1) {


...
Javascripts
...

<html>
<head></head>
<body>

html stuff and php code

</body>
</html>

} else {
header(&quot;Location: ?>

I'm not even gonna think about working on this until tomorrow.

One more thing though I've thought of... I have my required fields being validated with Javascript. Could be that those that haven't entered that info have Javascript disabled in their browser so that poses another thing to think about.

I take it php can validate form fields? Text fields are pretty simple but radio button and check boxes are another cup of tea.

REALLY appreciate your help, Rob!

Cheers,
Rhiannon
 
PHP can validate form fields before and after a page has loaded, but not while a user is working with it. Sounds like that's what you're basically doing anyway.

radio buttons and checkboxes aren't much worse than text boxes... the only problem is figuring out how to access them.

Using this little bit of code during debugging makes that much easier...

echo &quot;<pre>&quot;;
print_r($_GET);
print_r($_POST);
echo &quot;</pre>&quot;;

That will print out everything you're passing through forms to the screen and you'll be able to see how to access them in your PHP code.

-Rob
 
Okay, it's not working. I've got the code written as:

<?php
/* Script for second page */
if ($_POST[&quot;page_num&quot;] == 1) {


...
Javascripts
...

<html>
<head></head>
<body>

html stuff and php code

</body>
</html>

} else {
header(&quot;Location: ?>

I'm getting this error:
PHP Notice: Undefined index: page_num in c:\Inetpub\ on line 7 PHP Warning: Cannot modify header information - headers already sent in c:\Inetpub\ on line 9

I've deleted and the <? ?> tags in the php code in between the condition statement. The variable page_num is being set on page 1 and being passed to page 2 by a hidden field.

Rhiannon
 
One more thing...

When I start out on page 1 and click &quot;continue&quot; I get &quot;PHP Parse error: parse error, unexpected '<' in c:\Inetpub\ on line 9&quot;.

Apparently the variable page_num is being passed and the condition &quot;if ($_POST[&quot;page_num&quot;] == 1)&quot; is found to be true but when it continues and reaches the first javascript that's when it throws out this error.


Rhiannon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top