wright67uk Posted April 30, 2011 Share Posted April 30, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/235166-do-die-statements-and-echos-display-differently/ Share on other sites More sharing options...
trq Posted April 30, 2011 Share Posted April 30, 2011 die() outputs a string ands halts the script, echo outputs a string. Essentially they are the same. Quote Link to comment https://forums.phpfreaks.com/topic/235166-do-die-statements-and-echos-display-differently/#findComment-1208566 Share on other sites More sharing options...
wildteen88 Posted April 30, 2011 Share Posted April 30, 2011 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>"); } Quote Link to comment https://forums.phpfreaks.com/topic/235166-do-die-statements-and-echos-display-differently/#findComment-1208619 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.