Re: Two forms on one page

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Sorry for top posting!

FYI: You might want to check the math in your calculations.  It says that I am
41 when my birthday is tomorrow and I will be 36...

On 1/4/2011 10:08 AM, Jim Lucas wrote:
> On 1/4/2011 7:53 AM, Ethan Rosenberg wrote:
>> At 03:45 AM 1/4/2011, you wrote:
>>> Ethan,
>>>
>>> Ok, I would do this with what I would call wizard steps...
>>>
>>> On 1/3/2011 3:17 PM, Ethan Rosenberg wrote:
>>>> Oooops - left out the text that was supposed to be in the quotes.
>>>>
>>>> Dear List -
>>>>
>>>> I would like to have two(2) forms in one PHP script. I would like to
>>>> have the forms appear sequentially; ie, that the first form would
>>>> appear, the data would be entered, and then the second form would
>>>> appear, the data would be entered, and the script would exit.
>>>>
>>>> The code below displays both forms simultaneously. After the data is
>>>> entered for the first form, the second form appears again. After the
>>>> data is entered for the second form, the script displays the statement
>>>> "Enter your date of birth, in mm/dd/yyyy format: " from the first form.
>>>>
>>>> Would you please help me correct the script so that it will perform as
>>>> required.
>>>>
>>>> Thanks.
>>>>
>>>> Here is the code:
>>>> ============
>>>
> 
> To go back to what I originally wrote.  I found 1 error in the second form.
> Here is the corrected form.
> 
> <?php session_start(); ?>
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
> <html><body>
> <?php
> 
> switch ( @$_POST['next_step'] )
> {
>     case 'step3':
> 
>     if ( empty($_SESSION['dob']) )
>         die('DOB was not set in session...');
> 
>     $dateArr = explode('/', @$_SESSION['dob']);
> 
>     // calculate timestamp corresponding to date value
>     $dateTs = strtotime($_POST['dob']);
> 
>     // calculate timestamp corresponding to 'today'
>     $now = strtotime('today');
> 
>     // check that the value entered is in the correct format
>     if ( sizeof($dateArr) != 3 )
>         die('ERROR: Please enter a valid date of birth');
> 
>     // check that the value entered is a valid date
>     if ( !checkdate($dateArr[0], $dateArr[1], $dateArr[2]) )
>         die('ERROR: Please enter a valid date of birth');
> 
>     // check that the date entered is earlier than 'today'
>     if ( $dateTs >= $now )
>         die('ERROR: Please enter a date of birth earlier than today');
>     // calculate difference between date of birth and today in days
>     // convert to years
>     // convert remaining days to months
>     // print output
>     $ageDays = floor(($now - $dateTs) / 86400);
>     $ageYears = floor($ageDays / 365);
>     $ageMonths = floor(($ageDays - ($ageYears * 365)) / 30);
>     echo "You are approximately $ageYears years and $ageMonths months old.";
> 
>     break;
>     case 'step2':
>     $_SESSION['dob'] = @$_POST['dob'];
>     echo <<<FORM
> <form method="post" action="">
> <input type="hidden" name="next_step" value="step3" />
> Enter your kitten's name: <br />
> <input type="text" name="cat" />
> <input type="submit" name="submit" value="Submit Kitten" />
> </form>
> FORM;
> 
>     break;
>     case 'step1':
>     default:
> 
>     echo <<<FORM
> <form method="post" action="">
> <input type="hidden" name="next_step" value="step2" />
> Enter your date of birth, in mm/dd/yyyy format: <br />
> <input type="text" name="dob" />
> <input type="submit" name="submit" value="Submit" />
> </form>
> FORM;
> }
> ?>
> </body></html>
> 
> If this isn't it, I think you should explain (in sudo code) exactly the steps
> you are expecting things to.
> 
> Example sudo code
> 
> 1.  display form 'A'
> 2.  Person enters dob and presses submit
> 3.  processing script stores dob submitted
> 4.  display form 'B'
> 5.  person enters name of kitten and presses submit
> 6.  processing script retrieves dob previously stored
> 7.  calculate age
> 8.  display age
> ...
> 10. What happen to the kitten???
> 
> Form 'A':
> <form method="post" action="">
> <input type="hidden" name="next_step" value="step2" />
> Enter your date of birth, in mm/dd/yyyy format: <br />
> <input type="text" name="dob" />
> <input type="submit" name="submit" value="Submit" />
> </form>
> 
> Form 'B':
> <form method="post" action="">
> <input type="hidden" name="next_step" value="step3" />
> Enter your kitten's name: <br />
> <input type="text" name="cat" />
> <input type="submit" name="submit" value="Submit Kitten" />
> </form>
> 
> 
> Anyways, that is the idea.
> 
> Let us know.
> 
> Jim
> 
>> Please correct my errors.
>>
>> Thanks again.
>>
>> Ethan
>> +++++++
>>
>>> PHP General Mailing List (http://www.php.net/)
>>> To unsubscribe, visit: http://www.php.net/unsub.php
>>>
>>
>>
> 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux