Jump to content

[SOLVED] _temp Form Problem, Help!


SilentQ-noob-

Recommended Posts

this is my code in _form.php

<?  

if (isset($_POST['name'])) {
$name_temp = $_POST['name'];
} else {
$name_temp = "";
}
if (isset($_POST['lastname'])) {
$lastname_temp = $_POST['lastname'];
} else {
$lastname_temp = "";
}
  if (isset($_POST['email'])) {
$email_temp = $_POST['email'];
} else {
$email_temp = "";
}


?>

<caption color="red">All Fields Are Required</caption>
<table border="1">
<form action="form_complex_process.php" method="post">
<tr><td>Name:<input type="text" name="<? echo $name_temp; ?>" /><br /></td></tr>
<tr><td>Last Name: <input type="text" name="<? echo $lastname_temp; ?>" /></td></tr>
<tr><td>E-mail:<input type="text" name="<? echo $email_temp; ?>" /></td></tr>

</table>

<select name="dropdownbox">
<option value="chooseone"  selected >--Choose one--</option>
<option value="webmaster" <? if ($selecter=="webmaster") { echo " selected"; } ?>>Web Master</option>
<option value="programmer" <? if ($selecter=="programmer") { echo " selected"; } ?>>Programmer</option>
<option value="manager" name="selecter"<? if ($selecter=="manager") { echo " selected"; } ?>>Manager</option>
<option value="serveradministrator" <? if ($selecter=="serveradministrator") { echo " selected"; } ?>>Server Administrator</option>
</select>
<br />
<input type="radio" name="button1" value"subscribe" checked />I wish to subscribe
<input type="radio" name="button1" value"dontsubscribe" />No, I do not wish to subscribe
<input type="submit" value="Submit" />
</form>



</body>

 

this is my code in form_process.php

<body>
<style type="text/css">
<!--
.style4 {color:red}
-->
</style>

<?


$name = $_POST['name'];
$lastname = $_POST['lastname'];
$email = $_POST['email'];
$selecter = $_POST['dropdownbox'];
$errors = "";


if (empty($name)){
     $errors .="<span class='style4'>"."*The name field has not been filled out <br>"."</span>";
 }

if (empty($lastname)) {
     $errors .="<span class='style4'>"."*The last name field has not been filled out <br>"."</span>";
 }

if (empty($email)) {
      $errors .="<span class='style4'>"."*The email field has not been filled out <br>"."</span>";
  }
if( !strstr ($email, "@"   ) ) {
$errors .= "<span class='style4'>"."*Invalid e-mail<br>"."</span>";
}
if( !strstr ($email, "."   ) ) {
$errors .= "<span class='style4'>"."*Invalid e-mail<br>"."</span>";
}
if ($selecter == "chooseone" ) {
$errors .= "<span class='style4'>"."*You need to choose a Profession<br>"."</span>";
}

if (empty($errors)){
     echo "Thanks for filling out our form"; 
 }
else {
     echo $errors;
 include ("_form.php");


 }

?>

I'm trying to make the form re-appear with the values the user put in, but with the error message stating which one wasnt entered. For example, all but "name" is filled out, so form re-appears with previously entered data, but empty name field and "Name not entered" message. I thought this should work but all it does is print all the $error messages regardless of whether user entered data or not.

Link to comment
Share on other sites

i just built them as one for testing it seams ok

 

<body>
<style type="text/css">
<!--
.style4 {color:red}
-->
</style>

<?php

if( isset($_POST['dropdownbox']) )
{
$name = $_POST['name'];
$lastname = $_POST['lastname'];
$email = $_POST['email'];
$selecter = $_POST['dropdownbox'];
$errors = "";


if (empty($name)){
	 $errors .="<span class='style4'>"."*The name field has not been filled out <br>"."</span>";
	 }

if (empty($lastname)) {
	 $errors .="<span class='style4'>"."*The last name field has not been filled out <br>"."</span>";
	 }

if (empty($email)) {
	  $errors .="<span class='style4'>"."*The email field has not been filled out <br>"."</span>";
	  }
if( !strstr ($email, "@"   ) ) {
	$errors .= "<span class='style4'>"."*Invalid e-mail<br>"."</span>";
	}
	if( !strstr ($email, "."   ) ) {
	$errors .= "<span class='style4'>"."*Invalid e-mail<br>"."</span>";
	}
if ($selecter == "chooseone" ) {
	$errors .= "<span class='style4'>"."*You need to choose a Profession<br>"."</span>";
	}

if (empty($errors)){
	 echo "Thanks for filling out our form"; 
	 }else {
	 echo $errors;
	 //include ("_form.php");
	 }
}

if (isset($_POST['name'])) {
$name_temp = $_POST['name'];
} else {
$name_temp = "";
}
if (isset($_POST['lastname'])) {
$lastname_temp = $_POST['lastname'];
} else {
$lastname_temp = "";
}
  if (isset($_POST['email'])) {
$email_temp = $_POST['email'];
} else {
$email_temp = "";
}


?>

<caption color="red">All Fields Are Required</caption>
<table border="1">
<form method="post">
<tr><td>Name:<input type="text" name="<? echo $name_temp; ?>" /><br /></td></tr>
<tr><td>Last Name: <input type="text" name="<? echo $lastname_temp; ?>" /></td></tr>
<tr><td>E-mail:<input type="text" name="<? echo $email_temp; ?>" /></td></tr>

</table>

<select name="dropdownbox">
<option value="chooseone"  selected >--Choose one--</option>
<option value="webmaster" <? if ($selecter=="webmaster") { echo " selected"; } ?>>Web Master</option>
<option value="programmer" <? if ($selecter=="programmer") { echo " selected"; } ?>>Programmer</option>
<option value="manager" name="selecter"<? if ($selecter=="manager") { echo " selected"; } ?>>Manager</option>
<option value="serveradministrator" <? if ($selecter=="serveradministrator") { echo " selected"; } ?>>Server Administrator</option>
</select>
<br />
<input type="radio" name="button1" value"subscribe" checked />I wish to subscribe
<input type="radio" name="button1" value"dontsubscribe" />No, I do not wish to subscribe
<input type="submit" value="Submit" />
</form>



</body>

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.