TD Posted July 18, 2007 Share Posted July 18, 2007 Hi, could please someone help me out, i'm thinking how to do this for about a day, and can't solve the prob. When a user clicks on a car the option box selects what car has been choosed, after filling the form in and if he has forgotten to type some info, the script echos what did he forget, and the prob is, that the option value disappears. How can i save the value or post it over? Thanks ! P.S. sorry for my bad lang. <?php $t1=$_GET['t1']; switch($t1) { case "1": $t1v="selected='selected'"; $t2v=""; $t3v=""; break; case "2": $t1v=""; $t2v="selected='selected'"; $t3v=""; break; case "3": $t1v=""; $t2v=""; $t3v="selected='selected'"; break; } <form action="<? echo $_SERVER['PHP_SELF']; ?>" method="post"> <select name="auto"> <option value="Polo 1.4i" title="Polo 1.4i" <? echo $t1v?>>Polo 1.4i</option> <option value="Golf 1.6i" title="Golf 1.6i" <? echo $t2v?>>Golf 1.6i</option> <option value="Golf 1.9 TDI" title="Golf 1.9 TDI" <? echo $t3v?>>Golf 1.9 TDI</option> </select> </form> Quote Link to comment https://forums.phpfreaks.com/topic/60499-solved-option-value-remeber/ Share on other sites More sharing options...
phpknight Posted July 18, 2007 Share Posted July 18, 2007 Put the value in a session or cookie. That way you can remember the value and do this: if ($_SESSION['myVal']==1) $tv1="selected"; and so on. Quote Link to comment https://forums.phpfreaks.com/topic/60499-solved-option-value-remeber/#findComment-300962 Share on other sites More sharing options...
TD Posted July 18, 2007 Author Share Posted July 18, 2007 ok will try now, thx. Quote Link to comment https://forums.phpfreaks.com/topic/60499-solved-option-value-remeber/#findComment-300964 Share on other sites More sharing options...
DeadEvil Posted July 18, 2007 Share Posted July 18, 2007 <?php if($_GET['t1'] = "Polo 1.4i") $isSelected = "selected='selected'"; if($_GET['t1'] = "Golf 1.6i") $isSelected2 = "selected='selected'"; if($_GET['t1'] = "Golf 1.9 TDI") $isSelected3 = "selected='selected'"; ?> <form action="<? echo $_SERVER['PHP_SELF']; ?>" method="post"> <select name="auto"> <option value="Polo 1.4i" title="Polo 1.4i" <?=$isSelected?>>Polo 1.4i</option> <option value="Golf 1.6i" title="Golf 1.6i" <?=$isSelected2?>>Golf 1.6i</option> <option value="Golf 1.9 TDI" title="Golf 1.9 TDI" <?=$isSelected3?>>Golf 1.9 TDI</option> </select> </form> Quote Link to comment https://forums.phpfreaks.com/topic/60499-solved-option-value-remeber/#findComment-300974 Share on other sites More sharing options...
TD Posted July 18, 2007 Author Share Posted July 18, 2007 wow it works, big thx DeadEvil, many many thanks. Quote Link to comment https://forums.phpfreaks.com/topic/60499-solved-option-value-remeber/#findComment-300987 Share on other sites More sharing options...
DeadEvil Posted July 18, 2007 Share Posted July 18, 2007 your welcome. Quote Link to comment https://forums.phpfreaks.com/topic/60499-solved-option-value-remeber/#findComment-300989 Share on other sites More sharing options...
TD Posted July 18, 2007 Author Share Posted July 18, 2007 xmm i have not correctly tested, because the option box is always selecting the last option, so something is wrong it just wont remember. Quote Link to comment https://forums.phpfreaks.com/topic/60499-solved-option-value-remeber/#findComment-301001 Share on other sites More sharing options...
DeadEvil Posted July 18, 2007 Share Posted July 18, 2007 try this one <? <option value="Polo 1.4i" title="Polo 1.4i" <?=$isSelected?><? unset($isSelected) ?>>Polo 1.4i</option> <option value="Golf 1.6i" title="Golf 1.6i" <?=$isSelected2?><? unset($isSelected2']) ?>>Golf 1.6i</option> <option value="Golf 1.9 TDI" title="Golf 1.9 TDI" <?=$isSelected3?><? unset($isSelected3) ?>>Golf 1.9 TDI</option> ?> Quote Link to comment https://forums.phpfreaks.com/topic/60499-solved-option-value-remeber/#findComment-301003 Share on other sites More sharing options...
TD Posted July 18, 2007 Author Share Posted July 18, 2007 no reaction, the same.. ??? Quote Link to comment https://forums.phpfreaks.com/topic/60499-solved-option-value-remeber/#findComment-301005 Share on other sites More sharing options...
DeadEvil Posted July 18, 2007 Share Posted July 18, 2007 Error in operation I think "if($_GET['t1'] = "Polo 1.4i")" <?php if($_GET['t1'] == "Polo 1.4i") $isSelected = "selected='selected'"; if($_GET['t1'] == "Golf 1.6i") $isSelected2 = "selected='selected'"; if($_GET['t1'] == "Golf 1.9 TDI") $isSelected3 = "selected='selected'"; ?> <form action="<? echo $_SERVER['PHP_SELF']; ?>" method="post"> <select name="auto"> <option value="Polo 1.4i" title="Polo 1.4i" <?=$isSelected?>>Polo 1.4i</option> <option value="Golf 1.6i" title="Golf 1.6i" <?=$isSelected2?>>Golf 1.6i</option> <option value="Golf 1.9 TDI" title="Golf 1.9 TDI" <?=$isSelected3?>>Golf 1.9 TDI</option> </select> </form> Quote Link to comment https://forums.phpfreaks.com/topic/60499-solved-option-value-remeber/#findComment-301012 Share on other sites More sharing options...
phpknight Posted July 18, 2007 Share Posted July 18, 2007 You don't need the 'selected=' part. Just put SELECTED for the one you want. Quote Link to comment https://forums.phpfreaks.com/topic/60499-solved-option-value-remeber/#findComment-301013 Share on other sites More sharing options...
TD Posted July 18, 2007 Author Share Posted July 18, 2007 allright the code looks now so and the option values work, but it just wont remember, when i hit submit form. if($_GET['t1'] == "Polo 1.4i") $isSelected = "selected"; if($_GET['t1'] == "Golf 1.6i") $isSelected2 = "selected"; if($_GET['t1'] == "Golf 1.9 TDI") $isSelected3 = "selected"; <option value="Polo 1.4i" title="Polo 1.4i" <?=$isSelected?>>Polo 1.4i</option> <option value="Golf 1.6i" title="Golf 1.6i" <?=$isSelected2?>>Golf 1.6i</option> <option value="Golf 1.9 TDI" title="Golf 1.9 TDI" <?=$isSelected3?>>Golf 1.9 TDI</option> Quote Link to comment https://forums.phpfreaks.com/topic/60499-solved-option-value-remeber/#findComment-301026 Share on other sites More sharing options...
phpknight Posted July 18, 2007 Share Posted July 18, 2007 Like I said before, use a SESSION or COOKIE. Did you try that? HTML is a stateless protocol, so you have to make it remember something. session_start(); //on very top of script for both scripts if separate //on verification part $_SESSION['myValue']=1; //1, 2, or 3 if ($_SESSION['myValue'])==1) print "SELECTED"; //do the same for 2 or 3 Does that make sense? Quote Link to comment https://forums.phpfreaks.com/topic/60499-solved-option-value-remeber/#findComment-301036 Share on other sites More sharing options...
TD Posted July 18, 2007 Author Share Posted July 18, 2007 well i'm not familiar to sessions, could you please make a little sample for one car. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/60499-solved-option-value-remeber/#findComment-301040 Share on other sites More sharing options...
phpknight Posted July 18, 2007 Share Posted July 18, 2007 Could you give me the URL to this? That would be quicker. Also, send me the entire code for the page(s) so I can test it on my server and give you working code. Quote Link to comment https://forums.phpfreaks.com/topic/60499-solved-option-value-remeber/#findComment-301041 Share on other sites More sharing options...
TD Posted July 18, 2007 Author Share Posted July 18, 2007 http://www.racing.lv/car/ You can easy simulate the buttons self http://www.racing.lv/car/reg.php?t1=Golf%201.6i And after hit submit you will see that it just dont work. You need reg.php and form.php Quote Link to comment https://forums.phpfreaks.com/topic/60499-solved-option-value-remeber/#findComment-301045 Share on other sites More sharing options...
phpknight Posted July 18, 2007 Share Posted July 18, 2007 Am I missing something? If I click a choice, get the errors, and then click back, the option I chose is always highlighted in the drop-down box. I tested it twice for all of them. That is exactly what you want, right? I think it is the printed line under that you just forgot to change. Quote Link to comment https://forums.phpfreaks.com/topic/60499-solved-option-value-remeber/#findComment-301046 Share on other sites More sharing options...
TD Posted July 18, 2007 Author Share Posted July 18, 2007 Well yes with the back button it works, but mostly users just change immediatly all the form, they dont hit back, and if it's so, then the car vanishes and selects the first one. Quote Link to comment https://forums.phpfreaks.com/topic/60499-solved-option-value-remeber/#findComment-301048 Share on other sites More sharing options...
phpknight Posted July 18, 2007 Share Posted July 18, 2007 Oh, I see. I didn't actually wait that long to see the new form. First, I need the actual code because the PHP is of no use already having been executed on the server. Two ideas: 1. Just separate the form and the results. or 2. I can try to fix it, lol! Quote Link to comment https://forums.phpfreaks.com/topic/60499-solved-option-value-remeber/#findComment-301050 Share on other sites More sharing options...
TD Posted July 18, 2007 Author Share Posted July 18, 2007 Well i just thinked about your 1 idea, yes thats a option, but maybe if you get it really quick, without prob. then the 2 option would be much better. I would very appreciate it. Thanks for helping! The code you can easy save with save target as.. http://www.racing.lv/car/ Quote Link to comment https://forums.phpfreaks.com/topic/60499-solved-option-value-remeber/#findComment-301052 Share on other sites More sharing options...
phpknight Posted July 18, 2007 Share Posted July 18, 2007 Okay, give me a few minutes. Quote Link to comment https://forums.phpfreaks.com/topic/60499-solved-option-value-remeber/#findComment-301053 Share on other sites More sharing options...
TD Posted July 18, 2007 Author Share Posted July 18, 2007 will try Quote Link to comment https://forums.phpfreaks.com/topic/60499-solved-option-value-remeber/#findComment-301055 Share on other sites More sharing options...
adam_ Posted July 18, 2007 Share Posted July 18, 2007 make sure the if's have ==, not just =, otherwise they return always true Quote Link to comment https://forums.phpfreaks.com/topic/60499-solved-option-value-remeber/#findComment-301057 Share on other sites More sharing options...
phpknight Posted July 18, 2007 Share Posted July 18, 2007 This has changed the values to 1, 2, and 3, but this solves the specific problem I think. Forgive me for not using a switch. For some reason, I don't like them, lol. Let me know if it works. <body> <?PHP if (isset($_POST['auto'])) { $selected1=""; $selected2=""; $selected3=""; if ($_POST['auto']==1) $selected1="selected"; if ($_POST['auto']==2) $selected2="selected"; if ($_POST['auto']==3) $selected3="selected"; } ?> <form action="form.php" method="post"> <table width="530px"> <tr> <td align="left" width="90px">Auto:</td> <td align="left" width="190px"><select name="auto" style="width:175px"> <option value="1" title="Polo 1.4i" <?PHP print "$selected1";?>>Polo 1.4i</option> <option value="2" title="Golf 1.6i" <?PHP print "$selected2";?>>Golf 1.6i</option> <option value="3" title="Golf 1.9 TDI" <?PHP print "$selected3";?>>Golf 1.9 TDI</option> <input type="submit" name="submit" value="test" /> </TD> </tr> </table> </form> </BODY> Quote Link to comment https://forums.phpfreaks.com/topic/60499-solved-option-value-remeber/#findComment-301061 Share on other sites More sharing options...
TD Posted July 18, 2007 Author Share Posted July 18, 2007 yes it works - smoooth one.. Thanks!!!!! Quote Link to comment https://forums.phpfreaks.com/topic/60499-solved-option-value-remeber/#findComment-301074 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.