imperium2335 Posted April 14, 2009 Share Posted April 14, 2009 Hi, fairly simple request I think so here goes. I'd like to be able to have a form, but say if someone doesn't fill out a required field, they press submit, but the page stays and a little label next to the field they left empty. Whats best way to do this? Cheers. Quote Link to comment Share on other sites More sharing options...
PugJr Posted April 14, 2009 Share Posted April 14, 2009 Make a sumbit button with boxes and the such, self echo the page your own when pressed, and then when the button is submitted, you code it so each box, in this case would lets say $var is one box. Then check if ( $var == "" ) if so, echo whatever you want, then die();. Quote Link to comment Share on other sites More sharing options...
imperium2335 Posted May 22, 2009 Author Share Posted May 22, 2009 Die causes half the page not to load i have this: <form action="<?$_SERVER['PHP_SELF']?>" method="get"> <div id="uploadbox"> <div id="number"><img src="site-images/1.jpg" /></div> <p class="heading">Cake Details</p> <div id="names"> <p><span class="required">Name:</span></p> <p><span class="required">Tags:</span></p> </div> <div id="uploadfields"> <? if($cakename == NULL && $_SESSION['timeload'] != 1) { echo '<input name="cakename" type="text" class="mupinv" value="Name of the cake" />' ; } else { echo '<input name="cakename" type="text" class="mup" value="Name of the cake" />' ; } ?> Now the problem is that if a field isnt filled in everything is erased in the boxes when the user presses submit. Is there anyway to get the page to remember what they put in without wiping the fields if they have got one wrong? $_SESSION['timeload'] != 1 is to make all the boxes not red when the page first loads up. Thanks in advance. Quote Link to comment Share on other sites More sharing options...
fanfavorite Posted May 22, 2009 Share Posted May 22, 2009 Die causes half the page not to load When you call die() that means to stop executing at that point. <form action="<?$_SERVER['PHP_SELF']?>" method="get"> You can also do <form action="" method="get"> or <form action="" method="post">. <? if($cakename == NULL && $_SESSION['timeload'] != 1) { echo '<input name="cakename" type="text" class="mupinv" value="Name of the cake" />' ; } else { echo '<input name="cakename" type="text" class="mup" value="Name of the cake" />' ; } ?>[/code] Now the problem is that if a field isnt filled in everything is erased in the boxes when the user presses submit. Is there anyway to get the page to remember what they put in without wiping the fields if they have got one wrong? $_SESSION['timeload'] != 1 is to make all the boxes not red when the page first loads up. Thanks in advance. Try this: echo '<input name="cakename" type="text" class="'; if($cakename == NULL && $_SESSION['timeload'] != 1) { echo 'mupinv'; } else { echo 'mup'; } echo '" value="'; if ($_GET[cakename] != "") { echo $_GET[cakename]; } else { echo 'Name of the cake'; } echo '" />'; If you use method="post", then it would be $_POST[cakename]. Quote Link to comment Share on other sites More sharing options...
imperium2335 Posted May 22, 2009 Author Share Posted May 22, 2009 Thanks, worked a treat. 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.