frijole Posted March 27, 2008 Share Posted March 27, 2008 I am working on a registration script and I cannot figure out how to make the errors show up next to the text boxes that they refer to. Does anyone know how to do this? Link to comment https://forums.phpfreaks.com/topic/98196-how-to-get-from-errors-next-to-their-respective-fields/ Share on other sites More sharing options...
discomatt Posted March 27, 2008 Share Posted March 27, 2008 Make a custom error class? Link to comment https://forums.phpfreaks.com/topic/98196-how-to-get-from-errors-next-to-their-respective-fields/#findComment-502413 Share on other sites More sharing options...
BlueSkyIS Posted March 27, 2008 Share Posted March 27, 2008 I am working on a registration script and I cannot figure out how to make the errors show up next to the text boxes that they refer to. Does anyone know how to do this? include an echo for your error near the field. for instance, for a text field for Address: <?php echo $address_error; ?> <INPUT TYPE='text' VALUE='' NAME='address' SIZE='30'> so when the form is submitted and there is an error in the address, set $address_error = 'The error message.' and it will appear near the field. do this for all fields. Link to comment https://forums.phpfreaks.com/topic/98196-how-to-get-from-errors-next-to-their-respective-fields/#findComment-502424 Share on other sites More sharing options...
soycharliente Posted March 27, 2008 Share Posted March 27, 2008 I do something like this ... <?php if (isset($_POST['submit'])) { $error_name = empty($_POST['name']) ? TRUE : FALSE; $error_email = empty($_POST['email']) ? TRUE : FALSE; $errors = FALSE; if (!($error_name || $error_email)) { // process form, maybe redirect page } else { $errors = TRUE; } } // otherwise will show the form again, or for the first time ?> <?php echo ($errors) ? "<p>There are errors.</p>" : ""; ?> <form> <input type="text" name="name" value="<?php echo $name; ?>" /> <?php echo ($error_name) ? "Please enter your name." : ""; ?> <input type="text" name="email" value="<?php echo $email; ?>" /> <?php echo ($error_email) ? "Please enter your email." : ""; ?> <input type="submit" name="submit" value="Submit" /> </form> Link to comment https://forums.phpfreaks.com/topic/98196-how-to-get-from-errors-next-to-their-respective-fields/#findComment-502432 Share on other sites More sharing options...
frijole Posted March 27, 2008 Author Share Posted March 27, 2008 awesome, thanks a lot. It seems kind of obvious when someone else tells you. Thanks again. Link to comment https://forums.phpfreaks.com/topic/98196-how-to-get-from-errors-next-to-their-respective-fields/#findComment-502463 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.