Jump to content

Do die statements and echos display differently?


wright67uk

Recommended Posts

I have a problem with formating the appearance of a die statement.

As you will see from the css below, p.form and p.passed both have the same text-align, and marginal values,

however they display very differently.  P.passed is used in an echo, and P.form is used in a die.

I want to display both my echo and die statements in the same place.  Ive tried the obvious and played around with the margins on P.form but it doesnt seem to make any difference.  I can only presume that my die statement is ignoring the class im assigning it?

 

P.form

{

color:#FF03;

margin-left:100px;

text-align:left;

clear:both;

}

P.passed

{

color:#333;

margin-left:100px;

text-align:left;

clear:both;

}

 

<?php // snippet

if($Name == '')
{
	die ("<P class=\"form\">You did not complete the name field, please try again</p>");
}
elseif  ($Phone == '' or (preg_match("/^([1]-)?[0-9]{3}-[0-9]{3}-[0-9]{4}$/i", $Phone)))
{	
	die('<P class="form"> You completed the telephone field incorrectly, please try again</p>');
}		
elseif  ($Email == '' or (!filter_var($Email, FILTER_VALIDATE_EMAIL)))
{
	die('<P class="form"> You completed the Email field incorrectly, please try again</p>');
}									   
elseif  ($Postcode == '' or (!checkPostcode($Postcode)))
{
	die('<P class="form"> You did not complete the Postcode field correctly, please try again</p>');
}		  
elseif  ($Website == '' or (!preg_match("~^[a-z0-9.-]+\.(com|org|net|edu|co.uk)~i", $Website)))
{   																									
	die('<P class="form">You completed the website field incorrectly, please try again</p>');
}
else
{
	echo("<P class=\"passed\">Thankyou for submiting your details, you will be added to our directory shortly</p>");
}}

 

Ive formatted if and else slightly differently but the output is still the same.

Should die statements and echo's display differently?

Link to comment
Share on other sites

Killing the script for each instance where the user hasn't filled in the form correctly is bad application design.

 

You should instead add your error messages into an array when your validation for whaterver field fails, example for the Name field

	if($Name == '')
{
	$errors[] = '<P class="form">Name field left empty</p>';
}

 

When you have finished validating the user input you can check whether any errors have accrued. if there are errors then display them, along with the form. If there are no errors then display your success message.

if(!empty($errors))
{
    echo 'Sorry correct the following errors: <ul><li>' . implode('</li><li>', $errors);
    // display your form here
}
else
{
    echo("<P class=\"passed\">Thankyou for submiting your details, you will be added to our directory shortly</p>"); 
}

 

 

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.