Jump to content

Help with validation


kwdelre

Recommended Posts

Hi there,

 

I am working on getting my php form validation working. I just learned why mine wasn't working and it was because I had a header(location) in the middle of the html doc. The reason I had it there was because the code I am using is placed where I want the error to show. Here is the code I am using for this part. I only have one field being validated at the moment.

 

<?
session_start();

	  if ($_POST['submit']) {
		  
		  $_SESSION['City'] = $_POST['City'];
		  
		  $errors = "";
		  
		  if(!$_SESSION['City']){
			  $errors = $errors . "Please enter your city<br>";
	  }
	  if ($errors != "") {
		  echo "Please check the following errors:<br>";
		  echo $errors;
	  }
	  else {
		  header("Location: nextpage.php");
	  }
	  }

?>

 

My question is:

What way would you reorganize this (scrapy) validation to where I can redirect my user to a new page when there is no error value?

 

The form page submits to itself with POST.

 

Thanks for your help.

Link to comment
https://forums.phpfreaks.com/topic/227290-help-with-validation/
Share on other sites

NEVERMIND I got it....I'm such an amateur!

 

Now I have a different question.

 

My form validation works and all but as I'm testing it ($_POST['submit']) is staying true even when I refresh the page. I have to close Safari and reopen it. What can I do to stop this? Is it just because I am using a testing server?

 

I am using Safari because firefox won't display my php pages.

and I am using Xampp

 

Thanks!

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.