Jump to content

Simple PHP Redirect to URL using form variable.


nickfran

Recommended Posts

Hi, Sorry, I think this is an easy question but I'm a Web Designer not Developer and cannot find an answer to this question.

 

I'm designing a website for a client (a photographer) who wants her clients to proof their photos online.

I setup a website through simplescripts and a web script called ZenPhoto.

 

Each album is available by typing http://www.domain.com/proofs/album/album-id (I.E.) 123456789

 

I want to setup a form that sends the album-id and redirects them to the correct page.

 

Here's what I mean:

User clicks the Proofs link and is brought to a page with a form that says:

Please enter your Album ID: Text Field (named album) and a Submit Button.

 

Ideally when they click submit they would be redirected to http://www.domain.com/proofs/$album (What they entered in the text field). How do I set this up?

 

Please make it as simple as possible as I am new to PHP.

Thanks to anyone who can help me out!

- Nick

Link to comment
Share on other sites

add me to MSN my MSN is in my signature.. or I have my AIM on the left hand panel..

 

on topic though, you'd PROBABLY want javascript as there must be a reason for the htaccess usage there.. I'd do something like this:

 

<form onsubmit="function12()">

 

function function12() {

  top.location.href = "http://www.domain.com/proofs/album/"+document.getElementById("theInput'sID").value;

}

 

and! in the rare event if sum1 actually has javascirpt disabled.. set the form to go to whatever.php

 

and in whatever.php put this code

 

<?php

  header('Location: http://www.domain.com/proofs/album/'.$_POST['theInputsID']);

?>

Link to comment
Share on other sites

<?php

if (isset($_POST['album'])) {

  header("Location: http://www.domain.com/proofs/" . trim($_POST['album']));

}

 

@thorpe your response should have worked it looked like but I got the error:

 

Warning: Cannot modify header information - headers already sent by (output started at /home/user/public_html/directory/php/proof.php:6) in /home/user/public_html/directory/php/proof.php on line 9.

 

I tried removing whitespace and putting it on one line. Is there anything else that would be causing this problem? Something I may have left a space in between?

Link to comment
Share on other sites

Works Now!

Like I said, I'm a designer not developer and originally had this php code below the original <head> tag. Whoops!

 

Here is the code for all the world to see:

 

 

<?php if($_SERVER['REQUEST_METHOD'] == 'POST') : $albumid = $_POST['albumid']; header('Location: http://domain.com/proofs/' . $albumid); else:?>
<head>
<title>Domain.com Proofing</title>
</head>

<body>

<form action="<?php echo $_SERVER['../PHP_SELF']; ?>" method="post">
Album ID: <input type="text" name="albumid" />
<br />
<input type="submit" value="Go" />
</form>
<?php endif; ?>
</body>

 

Link to comment
Share on other sites

the php redirect should be used if Javascript isn't enabled on the client's browser.. otherwise the backbutton will push them back to the redirecting php page

 

meaning they'll go back 1 history element then get redirected again.. over and over.. a very huge inconvenience to the client.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.