homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

form post

 7:24 pm on Jul 30, 2009 (gmt 0)

i have a form i want to validate that the fields arent empty on the page of the form. i can do that no problem, but if i want to redirect to another page when they are filled out on submit and add an action to the:

<form action="nextpage.php" method="POST">

it just goes to the nextpage.php before it even validates it. is there a way to validate the fields before going to the next page?



 8:10 pm on Jul 30, 2009 (gmt 0)

perform the validation on nextpage.php or after you have validated the form data on the first page redirect them to nextpage.php using a header

//validate form
if($valid == true){
header("Location: nextpage.php");
echo "<p>Learn how to use my form!</p>";


 12:45 am on Jul 31, 2009 (gmt 0)

well i can validate on next page, except i want to do it on the page of the form. and it says headers already sent, because i already sent headers at the top of the page :/ like a redirect if a person doesnt meet requirements to view the page. so im assuming i cant use headers again, unless there is another way.


 6:35 am on Jul 31, 2009 (gmt 0)

you can, just begin the page with ob_start(); before you send anything else to the browser

then headers can be sent anywhere on the page


 7:00 am on Jul 31, 2009 (gmt 0)

An alternative would be Ajax validation.



 1:51 pm on Jul 31, 2009 (gmt 0)

Another alternative would be to use templates. If you use templates then you can do all sorts of validation and still write header information. As long as you set templates and never actually "echo" anything. The last alternative which may be quick and dirty but fitting for you would be to use JS. Something like this.
if(your form is valid){
echo("<SCRIPT language="JavaScript">


 3:22 am on Aug 1, 2009 (gmt 0)

Ok I got it to work I used ob_start() but anways, is there a way to still retrieve $_POST variables from the page since the form action is just
action="#" ?

 1:33 pm on Aug 3, 2009 (gmt 0)

As long as your code is in that page you can just request them via
$var = $_POST['yourName']; if it's going to another page before you validate then you need to either use get on your form method or use session variables.
$_SESSION['yourName'] = $_POST['yourName'];
You would need to do that on the page where they click the submit button. Now $_SESSION['yourName'] would be whatever value that post variable was, the entire time the users browser was open.


 3:30 pm on Aug 3, 2009 (gmt 0)

yeh i know i can use sessions but i dont want to use a bunch of sessions for something that people might not even follow through with. ill just post them on the same page :)


Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved