?
Solved

All inputs reset, why? form>formhadler>form and all's lost

Posted on 2003-03-04
12
Medium Priority
?
203 Views
Last Modified: 2006-11-17
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

0
Comment
Question by:chewonthat
  • 7
  • 5
12 Comments
 
LVL 15

Expert Comment

by:VGR
ID: 8067511
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?)
0
 

Author Comment

by:chewonthat
ID: 8067558
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
0
 
LVL 15

Expert Comment

by:VGR
ID: 8067790
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
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:chewonthat
ID: 8068040
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
0
 
LVL 15

Accepted Solution

by:
VGR earned 100 total points
ID: 8068091
depending on $_SESSION["radiobuttonvalue"], you would set an <OPTION> to be SELECTED :

(I guess you have a loop somewhere ?!? If not use this kind of code : )

<select name="hour" size="1" id="select6">
        <option <? echo ($_SESSION["radiobuttonvalue"]=='05am')?'SELECTED':''; ?>>05am</option>
[snip]
        <option <? echo ($_SESSION["radiobuttonvalue"]=='06am')?'SELECTED':''; ?>>06am</option>

the same for the CHECKED attribute of checkboxes
0
 

Author Comment

by:chewonthat
ID: 8068126
y did u put a 'radiobuttonvalue' in the hour drop down menu?

what's a loop?
0
 
LVL 15

Expert Comment

by:VGR
ID: 8068199
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
0
 

Author Comment

by:chewonthat
ID: 8068278
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

0
 

Author Comment

by:chewonthat
ID: 8068387
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>
0
 

Author Comment

by:chewonthat
ID: 8068807
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">
0
 
LVL 15

Expert Comment

by:VGR
ID: 8070218
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.
0
 

Author Comment

by:chewonthat
ID: 8073285
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">
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question