Redirect Question, Thanks for any help!

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
jwd
Forum Newbie
Posts: 3
Joined: Tue Dec 16, 2008 4:18 pm

Redirect Question, Thanks for any help!

Post by jwd »

Hi there... I'd appreciate any help... and I'm by no means asking anyone to do my work for me. If any knows of any tutorials or anything that may help me, I'd appreciate!

Basically I have a form (not an email form) that when you hit submit it calls another php file for the processing. In that file it has the header(Location:... for the redirect.

HOWEVER, I don't want it to redirect based on that. I want in the form to be able to specify a hidden field (or however best to do it) called "redirect" and the value be a URL.

So that way when someone clicks submit it will call the other php file to process (and ignore the headerLocation-- or I can just remove that) and then redirect to the page specified in the form.

THANKS so much in advance for any advice, help or pointing me somewhere to learn.
Reviresco
Forum Contributor
Posts: 172
Joined: Tue Feb 19, 2008 4:18 pm
Location: Milwaukee

Re: Redirect Question, Thanks for any help!

Post by Reviresco »

Assuming you have your URL in a variable called $url_for_redirect:

In the form:

Code: Select all

<input type="hidden" name="redirect" value="<?php echo $url_for_redirect; ?>"  />
In the form processing script:

Code: Select all

<?php
$url_to_go_to = $_POST['redirect'];
?>
 
At end of script:

Code: Select all

 
<?php
header('Location: ' . $url_to_go_to);
?>
 
jwd
Forum Newbie
Posts: 3
Joined: Tue Dec 16, 2008 4:18 pm

Re: Redirect Question, Thanks for any help!

Post by jwd »

I made a silly mistake, which is why I edited this to take it away.

That ended up working like a charm once I found what I did wrong.

Anyway- THANKS so much!
Post Reply