Jump to content

Need Someone Help :)


tauchai83

Recommended Posts

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?
Link to comment
https://forums.phpfreaks.com/topic/33574-need-someone-help/
Share on other sites

[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]
Link to comment
https://forums.phpfreaks.com/topic/33574-need-someone-help/#findComment-157231
Share on other sites

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 name
Ted.
Link to comment
https://forums.phpfreaks.com/topic/33574-need-someone-help/#findComment-157232
Share on other sites

<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.
Link to comment
https://forums.phpfreaks.com/topic/33574-need-someone-help/#findComment-157244
Share on other sites

i Already have all the require validation.

<?php


if($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>";
}else
if($Month == ''){
echo "<script>alert(\" Sorry! Please fill in your booking month.\");history.go(-1)</script>";
}else
if($Day == ''){
echo "<script>alert(\" Sorry! Please fill in your booking day.\");history.go(-1)</script>";
}else
if($Time == ''){
echo "<script>alert(\" Sorry! Please fill in your booking time.\");history.go(-1)</script>";
}
Link to comment
https://forums.phpfreaks.com/topic/33574-need-someone-help/#findComment-157252
Share on other sites

<td width="40%"><b>First Name</b> :</td>
<td width="50%"> <input type="text" name="f_name"  value="<?php echo $row["First_name"]; ?>">&nbsp;<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?

Link to comment
https://forums.phpfreaks.com/topic/33574-need-someone-help/#findComment-157255
Share on other sites

[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
Link to comment
https://forums.phpfreaks.com/topic/33574-need-someone-help/#findComment-157257
Share on other sites

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"
Link to comment
https://forums.phpfreaks.com/topic/33574-need-someone-help/#findComment-157330
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.