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
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!

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.