Jump to content

Help with form


Go to solution Solved by Barand,

Recommended Posts

when the user hits submit and all the fields are filled out it should print out a little welcome note, it is doing everything except that.. help please.. im sure its one of my true or false or something like that but I am lost right now. help please.. 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="EN" dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
<head>
<style>
body
{
background-color:#FF00FF;
}
h1
{
color:orange;
text-align:center;
}
p
{
font-family:"Times New Roman";
font-size:20px;
}
h1 {text-align:center;
}
</style>
<title>Assignment3</title>
</head>
<body>

<h1>Personal Information </h1>

<?php 
$fName = filter_input(INPUT_POST, "fName");
$lName = filter_input(INPUT_POST, "lName");
$city = filter_input(INPUT_POST, "city");
$state = filter_input(INPUT_POST, "state");
$zipCode = filter_input(INPUT_POST, "zipCode");
$other = filter_input(INPUT_POST, "other");

$chkErrors = FALSE;


if(!empty($_POST['fName']))
{
 $chkErrors = TRUE;
 }
 else
 {
 echo '****FIRST NAME FIELD REQUIRED*****';
  echo "<br> <a href='Assignment3.html'>Go back to form</a>";
	
	}
   


if(!empty($_POST['lName']))
{
 $chkErrors = TRUE;
 }
 else
 {
 echo '****LAST NAME FIELD REQUIRED*****';
  echo "<br> <a href='Assignment3.html'>Go back to form</a>";
	
	}
	
if(!empty($_POST['city']) && isset($_POST['city']))
{
 $chkErrors = TRUE;
 }
 else
 {
 echo '****CITY FIELD REQUIRED*****';
  echo "<br> <a href='Assignment3.html'>Go back to form</a>";
	
	}
	
if(!empty($_POST['state']))
{
 $chkErrors = TRUE;
 }
 else
 {
 echo '***STATE NAME FIELD REQUIRED*****';
  echo "<br> <a href='Assignment3.html'>Go back to form</a>";
	
	}


if(!empty($_POST['zipCode']))
{
 $chkErrors = TRUE;
 }
 else
 {
 echo '****ZIPCODE FIELD REQUIRED*****';
  echo "<br> <a href='Assignment3.html'>Go back to form</a>";
	
	}



if(!empty($_POST['other']))
{
 $chkErrors = TRUE;
 }
 else
 {
 echo '****TEXT FIELD REQUIRED*****';
  echo "<br> <a href='Assignment3.html'>Go back to form</a>";
	
	}


   
if ($chkErrors = FALSE) {


echo <<<HERE
'<h3> Hi there,  $fName $lName, <br /> so you live in $city,<br /> in the great state of $state.<br /> I hear the climate around $zipCode is great this time of year.
<br /> $fName, I hear that $state has alot to offer as far as recreation goes.<br />      <img src="pup.jpg" width="200" height="175"
alt="Cute Puppy" />
I hope that you have a great summer in $city. $other <br /></h3>'
HERE;
}



?>

</body>
</html> 
Edited by webdevdea
Link to comment
https://forums.phpfreaks.com/topic/279305-help-with-form/
Share on other sites

Your final test of chkerrors is incorrect.  ==

 

As for the whole logic - you set chkerrors to true if any one of the values is present.  Then at the end you are looking to see if chkerrors is false. Your handling of this obviates the need to even have $chkerrors at all.  Plus - you output an error message AND a link for every error.  You could end up with a rather silly looking page having 4-5 error messages with the same link repeated 4-5 times.

 

If I may offer a re-design:

To make it easier to follow, I'd use a var called $no_errors and set it to true to start. I'd also initialize $errmsg to ''. Then as I checked each value, if it was invalid I would set $no_errors to false and add an error message to $errmsg.   ($errmsg .= "this field is bad<br>";)

 

When I finished checking each value I would then check if $no_errors was still true.  If not I would then echo $errmsg and the <a> tag and exit.

Link to comment
https://forums.phpfreaks.com/topic/279305-help-with-form/#findComment-1436592
Share on other sites

not really sure where to put the errmsg you were talking about I have this working except when the user fills in the fields it does not generate the form

Your final test of chkerrors is incorrect.  ==

 

As for the whole logic - you set chkerrors to true if any one of the values is present.  Then at the end you are looking to see if chkerrors is false. Your handling of this obviates the need to even have $chkerrors at all.  Plus - you output an error message AND a link for every error.  You could end up with a rather silly looking page having 4-5 error messages with the same link repeated 4-5 times.

 

If I may offer a re-design:

To make it easier to follow, I'd use a var called $no_errors and set it to true to start. I'd also initialize $errmsg to ''. Then as I checked each value, if it was invalid I would set $no_errors to false and add an error message to $errmsg.   ($errmsg .= "this field is bad<br>";)

 

When I finished checking each value I would then check if $no_errors was still true.  If not I would then echo $errmsg and the <a> tag and exit.

<?php 
$fName = filter_input(INPUT_POST, "fName");
$lName = filter_input(INPUT_POST, "lName");
$city = filter_input(INPUT_POST, "city");
$state = filter_input(INPUT_POST, "state");
$zipCode = filter_input(INPUT_POST, "zipCode");
$other = filter_input(INPUT_POST, "other");
$errmsg = '';
$no_errors = TRUE;


if(!empty($_POST['fName']))
{
 $no_errors = FALSE;
 }
 else
 {
echo '***FIRST NAME FIELD REQUIRED*****';
 
	
	}
   


if(!empty($_POST['lName']))
{
$no_errors = FALSE;
 }
 else
 {
 echo '****LAST NAME FIELD REQUIRED*****';
 
	
	}
	
if(!empty($_POST['city']) && isset($_POST['city']))
{
$no_errors = FALSE;
 }
 else
 {
 echo '****CITY FIELD REQUIRED*****';
  
	
	}
	
if(!empty($_POST['state']))
{
$no_errors = FALSE;
 }
 else
 {
 echo '***STATE NAME FIELD REQUIRED*****';

	
	}


if(!empty($_POST['zipCode']))
{
$no_errors = FALSE;
 }
 else
 {
 echo '****ZIPCODE FIELD REQUIRED*****';
 
	
	}



if(!empty($_POST['other']))
{
$no_errors = FALSE;
 }
 else
 {
 echo '****TEXT FIELD REQUIRED*****';
 

	
	}
if ($no_errors = TRUE) {

echo "<br> <a href='Assignment3.html'>Go back to form</a>";
}

else

if ($no_errors == FALSE) {
echo "Hi there,  $fName $lName, <br /> so you live in $city,<br /> in the great state of $state.<br /> I hear the climate around $zipCode is great this time of year.
<br /> $fName, I hear that $state has alot to offer as far as recreation goes.<br />  
 I hope that you have a great summer in $city. $other <br />" ;

 }


   



?>
Link to comment
https://forums.phpfreaks.com/topic/279305-help-with-form/#findComment-1436601
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.