AdRock Posted February 23, 2007 Share Posted February 23, 2007 I would like to know if it is possible to change what is output when using the DIE function. At the moment I have just got an error message but this doesn't help becuase I have a form which is cleared when i go back from recieving the error message. I have validation that makes sure something is entered in the text boxes and if any fields are missing it displays the form again complete with any entered fields. I would like to know if there is alternative to using DIE so that I can echo the form again in case the user doesn't enter a certain field. The part of my code i want to check is the resizing of an image. If the user doesn't select a resizing option then it goes to this code below but I would like to redisplay the form again so the user doesn't lose everything they have entered //The code which resizes an image goes here else { die ('<strong>You didn\'t specify any resizing options.</strong>'); } Here is the code for my form complete with my validation $form=" <form enctype=\"multipart/form-data\" method=\"post\" action=\"$self\"> <p class=\"style1\">Please enter a title for the news article. <input class=\"form\" type=\"text\" title=\"Please enter a title for the news article\" name=\"txtName\" value=\"$name\" size=\"30\"/></p> <p class=\"style1\">Please enter the content for the news article. <textarea class=\"form\" title=\"Please enter the content for the news article\" name=\"txtMessage\" rows=\"25\" cols=\"30\">$message</textarea></p> <fieldset> <legend><b>Image Dimensions</b></legend> <div><label for \34image\">Image:</label> <input type=\"file\" name=\"image\"></br></div> <div><label for \"percent\">Resize to:</label> <input type=\"text\" name=\"percent\" size=\"1\" /> % (percentage)</div> <div><label for \"new_width\">OR new width:</label> <input type=\"text\" name=\"new_width\" size=\"1\" /> pixels (height will be calculated automatically)</br></div> <div><label for \"new_height\">OR new height:</label> <input type=\"text\" name=\"new_height\" size=\"1\" /> pixels (width will be calculated automatically) </br></div> <div><label class=\"left\" for \"both\">OR new height and new width:</label> <input type=\"text\" name=\"width\" size=\"1\" /> pixels</br> <input type=\"text\" name=\"width\" size=\"1\" /> pixels</br></div> </fieldset> <p class=\"style3\"> <input class=\"submit-button\" style=\"margin-left:0\" type=\"Submit\" name=\"submit\" value=\"Submit\"> </form>"; if($submit) { $valid=true; if( !$name ) { $errmsg.="Please enter a title for the news article:<br>"; $valid=false; } if( !$message) { $errmsg.="Please enter the content for the news article:<br>"; $valid=false; } } if( $valid !=true ) { echo( "<span style=\"font-weight: bold; color:red;\">".$errmsg."</span>" . $form ); } else { Also is it possible to do something similar when using the mysql_query function? Link to comment https://forums.phpfreaks.com/topic/39767-can-you-change-the-ouput-of-die-to-redisplay-form/ Share on other sites More sharing options...
Orio Posted February 23, 2007 Share Posted February 23, 2007 I often make a function, that shows a form with an error message and then dies. Example: <?php function die_form($err = "") { if($err != "") echo "<b>Error: ".$err."</b>"; echo "<form action=\"someaction.php\" method=\"POST\">"; echo "<input type=\"submit\" name=\"submit\" value=\"next page\">"; die(); } ?> As you can see, the $err variable is optional- you can call the function without an error to just display the form by calling die_form() and if you want to output an error, you pass it: die_form("Fill everything!"); Orio. Link to comment https://forums.phpfreaks.com/topic/39767-can-you-change-the-ouput-of-die-to-redisplay-form/#findComment-192040 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.