Link to home
Start Free TrialLog in
Avatar of chewonthat
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

Avatar of VGR
VGR

no, you can't do anything. This is standard HTML with FORMs.

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?)
Avatar of chewonthat

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
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
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
ASKER CERTIFIED SOLUTION
Avatar of VGR
VGR

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
y did u put a 'radiobuttonvalue' in the hour drop down menu?

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["listvalue"]==$i)?' SELECTED':'').">0".$i."am</option>";
}
echo "</select></p>";
?>

and the session variable $_SESSION["listvalue"] would contain only 5,6,7 or 8
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')?'SELECTED':''; ?>>05am</option>
          <option <? echo ($_SESSION["hour"]=='06am')?'SELECTED':''; ?>>06am</option>
          <option <? echo ($_SESSION["hour"]=='07am')?'SELECTED':''; ?>>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

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')?'SELECTED':''; ?>>05am</option>
          <option <? echo ($_SESSION["hour"]=='06am')?'SELECTED':''; ?>>06am</option>
          <option <? echo ($_SESSION["hour"]=='07am')?'SELECTED':''; ?>>07am</option>
          <option <? echo ($_SESSION["hour"]=='08am')?'SELECTED':''; ?>>08am</option>
          <option <? echo ($_SESSION["hour"]=='09am')?'SELECTED':''; ?>>09am</option>
            <option <? echo ($_SESSION["hour"]=='10am')?'SELECTED':''; ?>>10am</option>
            <option <? echo ($_SESSION["hour"]=='11am')?'SELECTED':''; ?>>11am</option>
            <option <? echo ($_SESSION["hour"]=='12pm')?'SELECTED':''; ?>>12pm</option>
            <option <? echo ($_SESSION["hour"]=='01pm')?'SELECTED':''; ?>>01pm</option>
            <option <? echo ($_SESSION["hour"]=='02pm')?'SELECTED':''; ?>>02pm</option>
            <option <? echo ($_SESSION["hour"]=='03pm')?'SELECTED':''; ?>>03pm</option>
            <option <? echo ($_SESSION["hour"]=='04pm')?'SELECTED':''; ?>>04pm</option>
            <option <? echo ($_SESSION["hour"]=='05pm')?'SELECTED':''; ?>>05pm</option>
            <option <? echo ($_SESSION["hour"]=='06pm')?'SELECTED':''; ?>>06pm</option>
            <option <? echo ($_SESSION["hour"]=='07pm')?'SELECTED':''; ?>>07pm</option>
            <option <? echo ($_SESSION["hour"]=='08pm')?'SELECTED':''; ?>>08pm</option>
            <option <? echo ($_SESSION["hour"]=='09pm')?'SELECTED':''; ?>>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>
took me awhile but i got it,
thanks
<input <? echo ($_SESSION["option"]=='day')?'CHECKED':''; ?> name="option" type="radio" value="day">
        10am-12pm through 1-4pm
        <input <? echo ($_SESSION["option"]=='evening')?'CHECKED':''; ?> type="radio" value="evening" name="option">
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.
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')?'SELECTED':''; ?>>05am</option>
         <option <? echo ($_SESSION["hour"]=='06am')?'SELECTED':''; ?>>06am</option>
         <option <? echo ($_SESSION["hour"]=='07am')?'SELECTED':''; ?>>07am</option>
         <option <? echo ($_SESSION["hour"]=='08am')?'SELECTED':''; ?>>08am</option>
                 </select>
<input <? echo ($_SESSION["option"]=='day')?'CHECKED':''; ?> name="option" type="radio" value="day">
       10am-12pm through 1-4pm
       <input <? echo ($_SESSION["option"]=='evening')?'CHECKED':''; ?> type="radio" value="evening" name="option">