chewonthat
asked on
All inputs reset, why? form>formhadler>form and all's lost
i have a form.php that is sent to a formhanlder.php where the user can look over his inputs, but by the time the user reads his data and clicks back to change something all the inputs have reset, is there anything i can do? I tried to register everything with sessions on the page prior to form.php but i'm not sure how that would work for drop down menus and radio buttons.
I'm just using a very basic post form with simple imputs and a simple handler.php (ie. "hello, <? echo $_SESSION['recipient'] ?> etc.) but if you need some code let me know
thanks, i'll keep working on it,
mikey
I'm just using a very basic post form with simple imputs and a simple handler.php (ie. "hello, <? echo $_SESSION['recipient'] ?> etc.) but if you need some code let me know
thanks, i'll keep working on it,
mikey
ASKER
hi, i got it to work (not reset) using sessions in the prior page to my form.php but not as i suspected for the radio buttons and drop down menu.
what exactly does the OnLoad handler have to look like,?
OnLoad="get back memorized values"?? and i assume it goes in form.php
thanks i'll give it a try
what exactly does the OnLoad handler have to look like,?
OnLoad="get back memorized values"?? and i assume it goes in form.php
thanks i'll give it a try
Onload="yourfunction(); return false;"
yourfunction is to be a jscript function between <SCRIPT> and </SCRIPT>
Anyway, if it worked via session variables, then it's OK
for the RB, it should work also
for the drop-down list (<SELECT> ?) too, just set the CHECKED and SELECTED elements depending on session variable
yourfunction is to be a jscript function between <SCRIPT> and </SCRIPT>
Anyway, if it worked via session variables, then it's OK
for the RB, it should work also
for the drop-down list (<SELECT> ?) too, just set the CHECKED and SELECTED elements depending on session variable
ASKER
unfortunately, i'm not exactly sure what you mean my 'just set the checked and elements depending on session variable'
here's my code how exactly would i incorporate the RB and Menu into my sessions (what would the following code have to look like, do you think you could give me an example, much appreciated)
prior page to form.php-
<?php
// start the session
session_start();
$txtName="your name";
// Create a new Session Value
session_register('txtName' );
// Register the input with the value
$_SESSION['txtName'] = $txtName;
?>
form.php
<body>
<form name="form1" method="post" action="formhandler.php">
<p>
<input name="txtName" type="text" id="txtName" value="<? echo $_SESSION['txtName']; ?>">
</p>
<p>day
<input type="radio" name="radiobutton" value="day">
night
<input type="radio" name="radiobutton" value="night">
<select name="hour" size="1" id="select6">
<option>05am</option>
<option>06am</option>
<option>07am</option>
<option>08am</option>
<option>09am</option>
</select></p>
</form>
</body>
then formhanler.php
thxs, mikey
here's my code how exactly would i incorporate the RB and Menu into my sessions (what would the following code have to look like, do you think you could give me an example, much appreciated)
prior page to form.php-
<?php
// start the session
session_start();
$txtName="your name";
// Create a new Session Value
session_register('txtName'
// Register the input with the value
$_SESSION['txtName'] = $txtName;
?>
form.php
<body>
<form name="form1" method="post" action="formhandler.php">
<p>
<input name="txtName" type="text" id="txtName" value="<? echo $_SESSION['txtName']; ?>">
</p>
<p>day
<input type="radio" name="radiobutton" value="day">
night
<input type="radio" name="radiobutton" value="night">
<select name="hour" size="1" id="select6">
<option>05am</option>
<option>06am</option>
<option>07am</option>
<option>08am</option>
<option>09am</option>
</select></p>
</form>
</body>
then formhanler.php
thxs, mikey
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
y did u put a 'radiobuttonvalue' in the hour drop down menu?
what's a loop?
what's a loop?
well, I don't know the name you'll choose for holding session-wide the radiobutton's value, so I've written radiobuttonvalue for you to adapt... easily... Except that I wrote "rdiobuttonvalue" in stead of "drop down list value :D SORRY
A loop is one of :
while...
do ... while ( == repeat ... until NOT ...)
for ...
foreach...
I said "do you have a loop" because usually when people output this kind of HTML :
<select name="hour" size="1" id="select6">
<option>05am</option>
<option>06am</option>
<option>07am</option>
<option>08am</option>
<option>09am</option>
</select></p>
it comes from this kind of code (containing a loop)
<?
echo "<select name=\"hour\" size=\"1\" id=\"select6\">";
for ($i=5;$i<=8;$i++) echo "<option>0".$i."am</option >";
}
echo "</select></p>";
?>
that's all... In which case the code <? echo ($_SESSION["listvalue"]==' 05am')?' SELECTED':''; ?> I suggested comes in only once, not copy-pasted...
and I would write it this way :
<?
echo "<select name=\"hour\" size=\"1\" id=\"select6\">";
for ($i=5;$i<=8;$i++) echo "<option".(($_SESSION["lis tvalue"]== $i)?' SELECTED':'').">0".$i."am< /option>";
}
echo "</select></p>";
?>
and the session variable $_SESSION["listvalue"] would contain only 5,6,7 or 8
A loop is one of :
while...
do ... while ( == repeat ... until NOT ...)
for ...
foreach...
I said "do you have a loop" because usually when people output this kind of HTML :
<select name="hour" size="1" id="select6">
<option>05am</option>
<option>06am</option>
<option>07am</option>
<option>08am</option>
<option>09am</option>
</select></p>
it comes from this kind of code (containing a loop)
<?
echo "<select name=\"hour\" size=\"1\" id=\"select6\">";
for ($i=5;$i<=8;$i++) echo "<option>0".$i."am</option
}
echo "</select></p>";
?>
that's all... In which case the code <? echo ($_SESSION["listvalue"]=='
and I would write it this way :
<?
echo "<select name=\"hour\" size=\"1\" id=\"select6\">";
for ($i=5;$i<=8;$i++) echo "<option".(($_SESSION["lis
}
echo "</select></p>";
?>
and the session variable $_SESSION["listvalue"] would contain only 5,6,7 or 8
ASKER
hey, i didn't mean any harm, i just honestly don't know. This is what i have so far for the drop down menu and it works great! thxs.
---------before form.php
<?php
// start the session
session_start();
$txtName="your name";
$hour="";
$rb="";
// Create a new Session Value
session_register('txtName' );
session_register('hour');
session_register('rb');
// Register the input with the value
$_SESSION['txtName'] = $txtName;
$_SESSION['hour'] = $hour;
$_SESSION['rb'] = $rb;
?>
------form.php
<select name="hour" size="1" id="select6">
<option <? echo ($_SESSION["hour"]=='05am' )?'SELECTE D':''; ?>>05am</option>
<option <? echo ($_SESSION["hour"]=='06am' )?'SELECTE D':''; ?>>06am</option>
<option <? echo ($_SESSION["hour"]=='07am' )?'SELECTE D':''; ?>>07am</option> </select>
SO now, i'd greatly appreciate it :) if you could provide an example of how to set up the radio buttons (rb) in the same manner (where does the <? echo $_SESSION['rb']; ?> actually need to go?), i've included the radio buttons i actually use on my form below, how would i modify them,
<input type="radio" value="day" checked name="rb">
10am-12pm through 1-4pm
<input type="radio" value="evening" name="rb">
5-10pm
---------before form.php
<?php
// start the session
session_start();
$txtName="your name";
$hour="";
$rb="";
// Create a new Session Value
session_register('txtName'
session_register('hour');
session_register('rb');
// Register the input with the value
$_SESSION['txtName'] = $txtName;
$_SESSION['hour'] = $hour;
$_SESSION['rb'] = $rb;
?>
------form.php
<select name="hour" size="1" id="select6">
<option <? echo ($_SESSION["hour"]=='05am'
<option <? echo ($_SESSION["hour"]=='06am'
<option <? echo ($_SESSION["hour"]=='07am'
SO now, i'd greatly appreciate it :) if you could provide an example of how to set up the radio buttons (rb) in the same manner (where does the <? echo $_SESSION['rb']; ?> actually need to go?), i've included the radio buttons i actually use on my form below, how would i modify them,
<input type="radio" value="day" checked name="rb">
10am-12pm through 1-4pm
<input type="radio" value="evening" name="rb">
5-10pm
ASKER
actually that loop is pretty cool, i'm just learning so php is still pretty confusing, here's my entire drop down menu for hour and minute. i don't know any better way to show the am, pm, with the minutes as i can only allow a time between 5am to 9:55pm.
<select name="hour" size="1" id="select6">
<option <? echo ($_SESSION["hour"]=='05am' )?'SELECTE D':''; ?>>05am</option>
<option <? echo ($_SESSION["hour"]=='06am' )?'SELECTE D':''; ?>>06am</option>
<option <? echo ($_SESSION["hour"]=='07am' )?'SELECTE D':''; ?>>07am</option>
<option <? echo ($_SESSION["hour"]=='08am' )?'SELECTE D':''; ?>>08am</option>
<option <? echo ($_SESSION["hour"]=='09am' )?'SELECTE D':''; ?>>09am</option>
<option <? echo ($_SESSION["hour"]=='10am' )?'SELECTE D':''; ?>>10am</option>
<option <? echo ($_SESSION["hour"]=='11am' )?'SELECTE D':''; ?>>11am</option>
<option <? echo ($_SESSION["hour"]=='12pm' )?'SELECTE D':''; ?>>12pm</option>
<option <? echo ($_SESSION["hour"]=='01pm' )?'SELECTE D':''; ?>>01pm</option>
<option <? echo ($_SESSION["hour"]=='02pm' )?'SELECTE D':''; ?>>02pm</option>
<option <? echo ($_SESSION["hour"]=='03pm' )?'SELECTE D':''; ?>>03pm</option>
<option <? echo ($_SESSION["hour"]=='04pm' )?'SELECTE D':''; ?>>04pm</option>
<option <? echo ($_SESSION["hour"]=='05pm' )?'SELECTE D':''; ?>>05pm</option>
<option <? echo ($_SESSION["hour"]=='06pm' )?'SELECTE D':''; ?>>06pm</option>
<option <? echo ($_SESSION["hour"]=='07pm' )?'SELECTE D':''; ?>>07pm</option>
<option <? echo ($_SESSION["hour"]=='08pm' )?'SELECTE D':''; ?>>08pm</option>
<option <? echo ($_SESSION["hour"]=='09pm' )?'SELECTE D':''; ?>>09pm</option>
</select>
</font><font color="black" size="1" face="Verdana"><strong>and </strong>< /font>
<font size="2" color="black" face="Verdana">
<select name="minute" size="1" id="select7">
<option selected>00 </option>
<option>05 </option>
<option>10 </option>
<option>15 </option>
<option>20 </option>
<option>25 </option>
<option>30 </option>
<option>35 </option>
<option>40 </option>
<option>45 </option>
<option>50 </option>
<option>55 </option>
</select>
<select name="hour" size="1" id="select6">
<option <? echo ($_SESSION["hour"]=='05am'
<option <? echo ($_SESSION["hour"]=='06am'
<option <? echo ($_SESSION["hour"]=='07am'
<option <? echo ($_SESSION["hour"]=='08am'
<option <? echo ($_SESSION["hour"]=='09am'
<option <? echo ($_SESSION["hour"]=='10am'
<option <? echo ($_SESSION["hour"]=='11am'
<option <? echo ($_SESSION["hour"]=='12pm'
<option <? echo ($_SESSION["hour"]=='01pm'
<option <? echo ($_SESSION["hour"]=='02pm'
<option <? echo ($_SESSION["hour"]=='03pm'
<option <? echo ($_SESSION["hour"]=='04pm'
<option <? echo ($_SESSION["hour"]=='05pm'
<option <? echo ($_SESSION["hour"]=='06pm'
<option <? echo ($_SESSION["hour"]=='07pm'
<option <? echo ($_SESSION["hour"]=='08pm'
<option <? echo ($_SESSION["hour"]=='09pm'
</select>
</font><font color="black" size="1" face="Verdana"><strong>and
<font size="2" color="black" face="Verdana">
<select name="minute" size="1" id="select7">
<option selected>00 </option>
<option>05 </option>
<option>10 </option>
<option>15 </option>
<option>20 </option>
<option>25 </option>
<option>30 </option>
<option>35 </option>
<option>40 </option>
<option>45 </option>
<option>50 </option>
<option>55 </option>
</select>
ASKER
took me awhile but i got it,
thanks
<input <? echo ($_SESSION["option"]=='day ')?'CHECKE D':''; ?> name="option" type="radio" value="day">
10am-12pm through 1-4pm
<input <? echo ($_SESSION["option"]=='eve ning')?'CH ECKED':''; ?> type="radio" value="evening" name="option">
thanks
<input <? echo ($_SESSION["option"]=='day
10am-12pm through 1-4pm
<input <? echo ($_SESSION["option"]=='eve
exactly, happy it works 8-) and that you learnt something :D
For looping through 5am to 9pm and inside those hours from 00 minuts to 59 minutes, I don't recommend a loop : your SELECT will end up with ***far too many*** values ; I recommend to keep a loop generating 05am to 9pm, and to add a standard INUPT TYPE=TEXT with maximum length set to 2 and control over its value so that it's 00 to 59
But why "grade C" ? This is infaming and people will see that you give away grades C for correct(AFAIK) answers.
Do as you wish, but I would recommend ***for you*** that you ask in Community Support to change the grade to "A". Personally I don't care.
For looping through 5am to 9pm and inside those hours from 00 minuts to 59 minutes, I don't recommend a loop : your SELECT will end up with ***far too many*** values ; I recommend to keep a loop generating 05am to 9pm, and to add a standard INUPT TYPE=TEXT with maximum length set to 2 and control over its value so that it's 00 to 59
But why "grade C" ? This is infaming and people will see that you give away grades C for correct(AFAIK) answers.
Do as you wish, but I would recommend ***for you*** that you ask in Community Support to change the grade to "A". Personally I don't care.
ASKER
Your probably right it doesn't hurt to give out A's. I wouldn't have learned as much, but i would have saved myself several hours trying to catch up to the level of related expertise that you presumed i had.
Just FYI here would have been my A answer=
Here's the code you need.
<select name="hour" size="1" id="select6">
<option <? echo ($_SESSION["hour"]=='05am' )?'SELECTE D':''; ?>>05am</option>
<option <? echo ($_SESSION["hour"]=='06am' )?'SELECTE D':''; ?>>06am</option>
<option <? echo ($_SESSION["hour"]=='07am' )?'SELECTE D':''; ?>>07am</option>
<option <? echo ($_SESSION["hour"]=='08am' )?'SELECTE D':''; ?>>08am</option>
</select>
<input <? echo ($_SESSION["option"]=='day ')?'CHECKE D':''; ?> name="option" type="radio" value="day">
10am-12pm through 1-4pm
<input <? echo ($_SESSION["option"]=='eve ning')?'CH ECKED':''; ?> type="radio" value="evening" name="option">
Just FYI here would have been my A answer=
Here's the code you need.
<select name="hour" size="1" id="select6">
<option <? echo ($_SESSION["hour"]=='05am'
<option <? echo ($_SESSION["hour"]=='06am'
<option <? echo ($_SESSION["hour"]=='07am'
<option <? echo ($_SESSION["hour"]=='08am'
</select>
<input <? echo ($_SESSION["option"]=='day
10am-12pm through 1-4pm
<input <? echo ($_SESSION["option"]=='eve
You should be able to overcome this using DHTML/JScript, though.
add an OnLoad event handler in your BODY tag,
get back memorized values OnLoad,
save actuel form's values OnUnload (OnExit?)