tauchai83 Posted January 10, 2007 Share Posted January 10, 2007 How to make the user input stay on all the field that he/she already filled up? what I mean is sometime user have enter wrong input for particular field, but he has to re-enter all field again because of just one mistake in a field, say email field. How to make the user input stay in there if they already make correct input? * in a form. Thanks...it will be good if some1 can send some coding as well.....i try to use history: go(-1) but don work..how? Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted January 10, 2007 Share Posted January 10, 2007 for input:[code]<input type="text" value="<?php echo $string?>">[/code]for text areas:[code]<textarea><?php echo $string?></textarea>[/code]and then set them to empty after data is correctly stored.Ted Quote Link to comment Share on other sites More sharing options...
tauchai83 Posted January 10, 2007 Author Share Posted January 10, 2007 how about for select drop down? got any javascript tat can be used? Quote Link to comment Share on other sites More sharing options...
taith Posted January 10, 2007 Share Posted January 10, 2007 [code]<?function form_autodropbox($to=array(),$selected="",$name=""){ if(!is_array($to)) return FALSE; $return .= '<select name="'.$name.'">'; foreach($to as $k => $v){ if($k==$selected) $return .= '<option selected value="'.$v.'">'.ucwords($k).'</option>'; else $return .= '<option value="'.$v.'">'.ucwords($k).'</option>'; } $return .= '</select>'; return $return;}echo form_autodropbox($to,$_POST[name],"name")?>[/code] Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted January 10, 2007 Share Posted January 10, 2007 Someone did an example for me, this is extracted out of my page:[code]<select name="birthday" size="1"><?php $bdays = array('01','02','03','04','05','06','07','08','09','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31',);$bday_select = "";foreach ($bdays as $bdays){$bday_select .= '<option value="' . $bdays . '"';if ($bdays == $birthday) {$bday_select .= ' selected';}$bday_select .= '>' . $bdays . '</option>';}echo "$bday_select";?></select>[/code]Where $birthday is the variable that you got from $birthday = $_POST['birthday'];the rest just change them, but remember, keep the same variables the same nameTed. Quote Link to comment Share on other sites More sharing options...
tauchai83 Posted January 10, 2007 Author Share Posted January 10, 2007 erm..thanks...but is it all have to use foreach loop? for input text type also nit such coding? just to make the data stay after the javascript have detected invalid input. Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted January 10, 2007 Share Posted January 10, 2007 sorry... i dont understand ??? Quote Link to comment Share on other sites More sharing options...
taith Posted January 10, 2007 Share Posted January 10, 2007 php runs before javascript... you set up the js using php, then the js can configure from there. Quote Link to comment Share on other sites More sharing options...
tauchai83 Posted January 10, 2007 Author Share Posted January 10, 2007 <form action="appointment2" method="POST" name="bkaddForm"> <tr> <td colspan="3"><strong><font size="5">Make Appointment</font></strong></td> </tr> <tr bgcolor="lightblue"> <td colspan="3"><font size="3">Please select date and time</font></td> </tr> <tr> <td colspan="3"><img src="images/dummy.gif"></td> </tr> <tr> <td width="9%"><b>Date :</b></td> <td width="52%"><SELECT name="Day"> <OPTION value="" selected>Day</OPTION> <OPTION value=01>1</OPTION> <OPTION value=02>2</OPTION> <OPTION value=03>3</OPTION> <OPTION value=04>4</OPTION> <OPTION value=05>5</OPTION> <OPTION value=06>6</OPTION> <OPTION value=07>7</OPTION> <OPTION value=08>8</OPTION> <OPTION value=09>9</OPTION> <OPTION value=10>10</OPTION> <OPTION value=11>11</OPTION> <OPTION value=12>12</OPTION> <OPTION value=13>13</OPTION> <OPTION value=14>14</OPTION> <OPTION value=15>15</OPTION> <OPTION value=16>16</OPTION> <OPTION value=17>17</OPTION> <OPTION value=18>18</OPTION> <OPTION value=19>19</OPTION> <OPTION value=20>20</OPTION> <OPTION value=21>21</OPTION> <OPTION value=22>22</OPTION> <OPTION value=23>23</OPTION> <OPTION value=24>24</OPTION> <OPTION value=25>25</OPTION> <OPTION value=26>26</OPTION> <OPTION value=27>27</OPTION> <OPTION value=28>28</OPTION> <OPTION value=29>29</OPTION> <OPTION value=30>30</OPTION> <OPTION value=31>31</OPTION> </SELECT>it seems ur coding as same as this...The data never stay after the user has selected it on screen..ok..let me explain in details....The Date require user to input Day Month Year separtely as shown above. Let say the user forgot to enter Month and year, only Day...Javascript will display some some error message (validation). After clicking 'OK" of the message pop up, the data of the Day should remain there. Just like when u fill a form to register..just because email invalid, u don have 2 re-enter again for the other field that already correctly enter. Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted January 10, 2007 Share Posted January 10, 2007 What I think is easier if you used all php, so smt like this:[code]if ($year == "" or $month == "") {echo "You have not fill in the required fields";}[/code] Quote Link to comment Share on other sites More sharing options...
tauchai83 Posted January 10, 2007 Author Share Posted January 10, 2007 i Already have all the require validation.<?phpif($Year=='' and $Month=='' and $Day ==''){ echo "<script>alert(\" Sorry! Please fill in your booking date.\");history.go(-1)</script>";}else if($Year=='' and $Month==''){ echo "<script>alert(\" Sorry! Please fill in your booking Month and Year.\");history.go(-1)</script>";}else if($Year=='' and $Day==''){ echo "<script>alert(\" Sorry! Please fill in your booking Day and Year.\");history.go(-1)</script>";}else if($Month=='' and $Day==''){ echo "<script>alert(\" Sorry! Please fill in your booking Day and Month.\");history.go(-1)</script>";}else if($Year == ''){ echo "<script>alert(\" Sorry! Please fill in your booking year.\");history.go(-1)</script>";}elseif($Month == ''){ echo "<script>alert(\" Sorry! Please fill in your booking month.\");history.go(-1)</script>";}elseif($Day == ''){ echo "<script>alert(\" Sorry! Please fill in your booking day.\");history.go(-1)</script>";}elseif($Time == ''){ echo "<script>alert(\" Sorry! Please fill in your booking time.\");history.go(-1)</script>";} Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted January 10, 2007 Share Posted January 10, 2007 okay, thats cool, does the <?php echo $string?> thing works for textareas and input fields? or they dont work at all as well, or is it just the drop down box which doesnt work?Ted Quote Link to comment Share on other sites More sharing options...
tauchai83 Posted January 10, 2007 Author Share Posted January 10, 2007 <td width="40%"><b>First Name</b> :</td> <td width="50%"> <input type="text" name="f_name" value="<?php echo $row["First_name"]; ?>"> <font color="#FF0000" size="2">(*) Require field</font></td> <td width="10%"></td>the value of this "echo" is retrive from Database Mysql. ur method echo $string is retrieved frm DB or from the user input on the form? Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted January 10, 2007 Share Posted January 10, 2007 [code]<?php if(isset($_POST['submit'])){$name = $_POST['name'];$birthday = $_POST['birthday'];if ($birthday == "" or $name == "") {echo"<p>(Required field(s) are left blank)</p>";$invalid = TRUE;}if ($invalid == FALSE) {require("mysqlconnection.php");$insert = mysql_query("INSERT INTO user(name, birthday) VALUES('$name', '$birthday')")//or other types of storing you wish.$birthday = ""; $name = "";//set them empty after storage.}}//form below:?><form name="test" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"><input name="username" value="<?php echo"$name"?>" type="text" size="30" maxlength="20" /><select name="birthday" size="1"><?php $bdays = array('01','02','03','04','05','06','07','08','09','10','11','12','13','14','15','16', '17','18','19','20','21','22','23','24','25','26','27','28','29','30','31',);$bday_select = "";foreach ($bdays as $bdays){$bday_select .= '<option value="' . $bdays . '"';if ($bdays == $birthday) {$bday_select .= ' selected';}$bday_select .= '>' . $bdays . '</option>';}echo"$bday_select";?></select></form>[/code]This is an example of my page that works, hope it does help you.Ted Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted January 10, 2007 Share Posted January 10, 2007 user inputis this a signup type form or an edit type form?Ted Quote Link to comment Share on other sites More sharing options...
tauchai83 Posted January 10, 2007 Author Share Posted January 10, 2007 sign up type..haha.....u are helpful...i going through ur source code..does it work on ur pc? the data that already correctly enter by user stay or not in a field? Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted January 10, 2007 Share Posted January 10, 2007 it stays on the fields, i tried. Quote Link to comment Share on other sites More sharing options...
tauchai83 Posted January 10, 2007 Author Share Posted January 10, 2007 yes! thanks! it stay! finally!....input text is easir than select drop down....thanks! problems solved! Thanls ya Ted Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted January 10, 2007 Share Posted January 10, 2007 welcom. i am gald to hear that.. ;D Quote Link to comment Share on other sites More sharing options...
tauchai83 Posted January 10, 2007 Author Share Posted January 10, 2007 ted,the drop down select however, does not work as intended. I have tried ur coding...can u help 2 solve the day select. user input does not stay... Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted January 10, 2007 Share Posted January 10, 2007 try this:<?php function check($a,$b){if($a == $b){echo " selected=\"selected\"";}}?><select name="test"><option value="1" <?php check("1",$b)?>>Test1</option><option value="2" <?php check("2",$b)?>>Test2</option><option value="3" <?php check("3",$b)?>>Test3</option><option value="4" <?php check("4",$b)?>>Test4</option></select>replace $b with your strings which should be something like "$day" Quote Link to comment Share on other sites More sharing options...
tauchai83 Posted January 10, 2007 Author Share Posted January 10, 2007 stil..it doesn't work..haha....any more idea? do u ever do this kind coding? select data stay there.... 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.