Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
PHP Redirect based on Variable Defined by Form Submission?
Old 01-02-2010, 12:20 AM PHP Redirect based on Variable Defined by Form Submission?
Junior Talker

Posts: 4
Trades: 0
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
webdesignkid is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 01-02-2010, 02:55 AM Re: PHP Redirect based on Variable Defined by Form Submission?
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Just to clarify, all the form does is redirect to the page corresponding to the given id?
PHP Code:
<?php
if($_SERVER['REQUEST_METHOD'] == 'POST') :
     
$albumid $_POST['albumid'];
     
header('Location: http://domain.com/proofs/album/' $albumid);
else:
?>
<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; ?>
That's just an example; you may want to also validate the albumid and handle cases where it is not valid after submission.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Last edited by NullPointer; 01-02-2010 at 03:02 AM..
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 01-02-2010, 01:01 PM Re: PHP Redirect based on Variable Defined by Form Submission?
Junior Talker

Posts: 4
Trades: 0
@NullPointer 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?
webdesignkid is offline
Reply With Quote
View Public Profile
 
Old 01-02-2010, 03:25 PM Re: PHP Redirect based on Variable Defined by Form Submission?
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
You cannot call header if any output has been sent. Can you post your entire script?
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 01-03-2010, 11:37 AM Re: PHP Redirect based on Variable Defined by Form Submission?
Junior Talker

Posts: 4
Trades: 0
Works Now!
Like I said, I'm a designer not developer and originally had this content below the original <head> tag. Whoops!

Here is the code for all the world to see:


Code:
<?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>
webdesignkid is offline
Reply With Quote
View Public Profile
 
Old 01-09-2010, 06:15 PM Need a little more info.
Junior Talker

Posts: 3
Trades: 0
The code listed is exactly what I am needing, however my php is little to none.

I understand the gist of what is going on here but whenever I use either example of code my redirect ends up being:

http://www.mydomain.com/<?php%20echo%20$_SERVER['PHP_SELF'];%20?>

I tried having the first part of the php above and below the <header>

I also tried making an independent php file which did not work.

I tried copying the "working" code into a fresh html file and resulted in the same problem.

Can someone give me a couple extra steps to make using this code a little easier?

Thanks a bunch!
jsgora is offline
Reply With Quote
View Public Profile
 
Old 01-09-2010, 06:27 PM Re: PHP Redirect based on Variable Defined by Form Submission?
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Quote:
I tried copying the "working" code into a fresh html file and resulted in the same problem.
PHP will not run unless the file extension is .php
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 01-09-2010, 06:47 PM Re: PHP Redirect based on Variable Defined by Form Submission?
Junior Talker

Posts: 3
Trades: 0
Ah thanks, I re-ran it as a .php and it worked fine with one minor tweak.

Thanks
jsgora is offline
Reply With Quote
View Public Profile
 
Old 01-09-2010, 07:04 PM Re: PHP Redirect based on Variable Defined by Form Submission?
Junior Talker

Posts: 3
Trades: 0
I am not sure how to add validation to cancel redirect if the field is empty. Any ideas?

Thanks!
jsgora is offline
Reply With Quote
View Public Profile
 
Old 01-10-2010, 12:31 AM Re: PHP Redirect based on Variable Defined by Form Submission?
Experienced Talker

Posts: 32
Name: Dan
Location: New Zealand
Trades: 0
There is no security on that code, it should be:

Code:
$albumid = (int) $_POST['albumid'];
The (int) makes sure it's an INTEGER, and if it's not it just comes out as 0, so to cancel it if the validation is incorrect you would do:

Code:
<?php 
if($_SERVER['REQUEST_METHOD'] == 'POST') : 
     $albumid = (int) $_POST['albumid']; 
if($albumid > 0):
     header('Location: http://domain.com/proofs/album/' . $albumid); 
endif;
else: 
?> 
<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; ?>
__________________

Please login or register to view this content. Registration is FREE
/ PHP Web Development and Design Services

Please login or register to view this content. Registration is FREE
Awesome new Facebook app
Rumadon is offline
Reply With Quote
View Public Profile Visit Rumadon's homepage!
 
Old 01-10-2010, 12:45 AM Re: PHP Redirect based on Variable Defined by Form Submission?
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Quote:
Originally Posted by Rumadon View Post
There is no security on that code

The (int) makes sure it's an INTEGER, and if it's not it just comes out as 0
Not quite. If you cast to an integer in PHP you're telling PHP to try to convert the given value to an integer value. Notice that this isn't the same as ensuring that the given value is an integer:

PHP Code:
echo (int) is_numeric('123abc'); //will output 0
echo (int) '123abc';  //will output 123 
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Last edited by NullPointer; 01-10-2010 at 12:47 AM..
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Reply     « Reply to PHP Redirect based on Variable Defined by Form Submission?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.40775 seconds with 12 queries