tqla Posted December 5, 2007 Share Posted December 5, 2007 Hello. On my form when the Submit button is clicked my script checks for blank fields. If it finds blanks it shows a message. The problem is that it shows the blank fields in their variable name. I'd like to change the alert to show the same names on the form. Here's the code: if(isset($blanks)) { $message_new = "The following fields are blank. Please enter the required information:<br /> "; foreach($blanks as $value) { $message_new .= "$value<BR /> "; } extract($_POST); include("form.inc"); exit(); } The problem is that the read out reads like this: The following fields are blank. Please enter the required information: firstName lastName title company street city state zip telephone email I'd like to change the message to show the names just like they are on the form. Like this: Last Name Title Company Street City State Zip Telephone Email Address The thing is that it can only SHOW it like this but it can't permanantly change the variable because it needs to stay in this form to populate the database. firstName lastName title company street city state zip telephone email Ya know what I mean? Thanks. Quote Link to comment Share on other sites More sharing options...
PHP_PhREEEk Posted December 5, 2007 Share Posted December 5, 2007 You need to build an array that holds the Titles, and $blanks should be populated with corresponding keys. That way, you can just echo the Title array key using foreach. If you post the rest of the code, I can help you with it (need all of it, really). PhREEEk Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted December 5, 2007 Share Posted December 5, 2007 Here is an example of how you can do it <?php if (isset($_POST['submit'])){ $message = ""; //check for empty values if (!isset($_POST['f1']) || empty($_POST['f1'])) $message .= "<br>f1"; if (!isset($_POST['f2']) || empty($_POST['f2'])) $message .= "<br>f2"; if (!isset($_POST['f3']) || empty($_POST['f3'])) $message .= "<br>f3"; if ($message != ""){ echo "The following fields are blank. Please enter the required information:"; echo $message; } else { echo "Everything was filled in"; } } ?> <p> <form method="post"> <input type="text" name="f1"><br> <input type="text" name="f2"><br> <input type="text" name="f3"><br> <input type="submit" name="submit"> </form> Quote Link to comment Share on other sites More sharing options...
tqla Posted December 6, 2007 Author Share Posted December 6, 2007 Thank you for the help. Took a few hours but I got it working. Quote Link to comment 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.