Jump to content

Error Checks Only Working For Empty Fields?


son

Recommended Posts

I have this feedback form which causes an empty page for anything after the heading once a value for either feedback, source or both are entered. Leaving the fields empty and pressing submit brings the correct messages (This is required field). Printing the $_POST values clearly shows that the data is entered. I really do not understand and would appreciate your help (my head starts smoking now, I really cannot spot the problem). The code is:

<h2 style="margin-bottom:5px;" ><strong>Feedback page</strong></h2><?phpif (isset($_POST['submitted']))	{print_r ($_POST);//initialise error array  $errors = array();	if (!isset($_POST['feedback']) OR empty($_POST['feedback'])) {	$feedback = FALSE;	$errors['feedback'] = '\'Feedback\' is a required field';		}	else	{	$feedback = escape_data($_POST['feedback']);	}	if (!isset($_POST['source']) OR empty($_POST['source'])) {	$source = FALSE;	$errors['source'] = '\'Your details\' is a required field';		} else	{		$source = escape_data($_POST['source']);	}	if ($feedback && $source)	{	$query2 = "INSERT INTO feedback (feedback, source, active) VALUES ('$feedback', '$source', 'n')";	if ($result2 = mysqli_query ($dbc, $query2))	{		echo "<p>Thank you for your feedback!</p>";		}	else	{		echo "<p>Your submission could not be processed due to a system error.</p>";		}	}	else	{	echo "<p>Some of your entries need to be amended.</p>";	}}	else	{			echo "<p>Please leave your feedback.</p>";}function check_error ($field, $text) {  global $errors;  if (empty($errors[$field])) {    echo $text;  } else {    echo "<strong>" . $errors[$field] . "</strong>";  }}?><form action="feedback.php" method="post"><p><label for="feedback"><?php echo check_error('feedback', 'Your feedback*'); ?></label><br  /><textarea cols="35" rows="4" name="feedback" id="feedback"><?php if (isset($_POST['feedback'])) echo $_POST['feedback']; ?></textarea></p><p><label for="source"><?php echo check_error('source', 'Your details*'); ?></label><br  /><textarea cols="35" rows="1" name="source" id="source"><?php if (isset($_POST['source'])) echo $_POST['source']; ?></textarea></p><p style="text-align:right; margin-top:25px;"><input type="hidden" name="submitted" value="TRUE" /><input type="submit" value="Submit" name="submit" /></p></form><p class="empty"> </p></div></div>

Son

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...