nickfran Posted January 2, 2010 Share Posted January 2, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/186901-simple-php-redirect-to-url-using-form-variable/ Share on other sites More sharing options...
trq Posted January 2, 2010 Share Posted January 2, 2010 <?php if (isset($_POST['album'])) { header("Location: http://www.domain.com/proofs/" . trim($_POST['album'])); } Place this within a script, then simply point your form's action to this script. Quote Link to comment https://forums.phpfreaks.com/topic/186901-simple-php-redirect-to-url-using-form-variable/#findComment-987000 Share on other sites More sharing options...
RussellReal Posted January 2, 2010 Share Posted January 2, 2010 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']); ?> Quote Link to comment https://forums.phpfreaks.com/topic/186901-simple-php-redirect-to-url-using-form-variable/#findComment-987002 Share on other sites More sharing options...
nickfran Posted January 2, 2010 Author Share Posted January 2, 2010 <?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? Quote Link to comment https://forums.phpfreaks.com/topic/186901-simple-php-redirect-to-url-using-form-variable/#findComment-987213 Share on other sites More sharing options...
RussellReal Posted January 2, 2010 Share Posted January 2, 2010 You need to put his at the very top of the page and no white space around the php tags.. the javascript example I showed you should work. Quote Link to comment https://forums.phpfreaks.com/topic/186901-simple-php-redirect-to-url-using-form-variable/#findComment-987235 Share on other sites More sharing options...
nickfran Posted January 3, 2010 Author Share Posted January 3, 2010 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> Quote Link to comment https://forums.phpfreaks.com/topic/186901-simple-php-redirect-to-url-using-form-variable/#findComment-987674 Share on other sites More sharing options...
RussellReal Posted January 3, 2010 Share Posted January 3, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/186901-simple-php-redirect-to-url-using-form-variable/#findComment-987710 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.