Jump to content

Recommended Posts

For some reason this script returns two extra numbers (even though the form only submits letters) when I am returning the $value variable in the section that processes the form. The form is only four fields long, but when I echo $value, it shows the four values from the form plus two more values. I'm a little confused. Hopefully someone can help.

 

<?php



if ($action != processform)
{
dateForm();
}




if ($action == processform)
{
$badform = "no";
foreach ($_POST as $field => $value)
{
  if ($value == "")
{
	echo "<font color='red'>You have not filled in a ";
	convertLabel($field);
	echo "!<br></font>";
	$badform = "yes";
}
echo "$value";
if (!ereg("^[A-Za-z '-]{0,50}$",$value) )
{
	echo "<font color='red'>";
	convertLabel($field);
	echo " has invalid characters!<br></font>";
	$badform = "yes";
}
}
}



if ($badform == "yes")
{
	dateForm();
}
if ($badform == "no")
{
	echo "Success!";
}


function dateForm()
{
	echo "<b>
		<font size='4'>Add A Date!</font><br><br>";

		$labels = array ("Date_Name" => "Date's Name",
                 "Date_School" => "Date's School",
                 "Date_City" => "Date's City",
                 "Date_State" => "Date's State");

	echo "<form action='newdate.php?action=processform' method='POST'>\n";
	foreach ($labels as $field => $label)
	{
		$value = $_POST[$field];
		echo "$label <br><input type='text' name='$field' value='$value' size='50' maxlength '50'>";
			if ($field == "Date_School")
				{
					echo " </b><font size='2'><a href='newschool.php'>New School?</a></font><b>";
				}
		echo "<br><br>\n";
	}

	echo "<input type='image' SRC='images/adddatebutton.png' ALT='Submit button'></form>";
}


function convertLabel($field)
{
if ($field == "Date_Name")
	{
		$label = "Date Name";
	}
if ($field == "Date_School")
	{
		$label = "Date School";
	}
if ($field == "Date_City")
	{
		$label = "Date City";
	}
if ($field == "Date_State")
	{
		$label = "Date State";
	}
	echo "$label";
}

?>

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.