Two forms on one page

Two forms on one page

am 03.01.2011 23:52:02 von Ethan Rosenberg

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 "" from the first form.

Would you please help me correct the script so that it will perform
as required.

Thanks.

Here is the code:
============
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">



global $todo;

// if form not yet submitted
// display form
if ( isset($_POST['cat']) && $_POST['submit'] === 'Submit Ktten' )
die();


if ( isset($_POST['submit']) && $_POST['submit'] === 'Submit' )
agerdo();
else
{
echo "

";
echo "Enter your date of birth, in mm/dd/yyyy format:
";
echo "";
echo "";
echo "
";
}


function agerdo()

{
global $todo;
// echo $todo;
// process form input
// split date value into components
$dateArr = explode('/', $_POST['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.";
}

if ( isset($_POST['submit']) && $_POST['submit'] === 'Submit Kitten' )
catdo();
if ( !isset($_POST['cat'])) //&& $_POST['submit'] === 'Submit Kitten' )

{
echo <<

Enter your kitten's name:




HTML;
}

function catdo()
{


$name_cat = $_POST['cat'];
echo "Your Kitten is $name_cat";
exit();
}


?>


===========
Ethan

MySQL 5.1 PHP 5 Linux [Debian (sid)]



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

Re: Two forms on one page

am 04.01.2011 00:12:52 von Toby Hart Dyke

On 1/3/2011 10:52 PM, Ethan Rosenberg wrote:
> 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
> "" from the first form.
>
> Would you please help me correct the script so that it will perform as
> required.

If you're trying to do this without actually submitting the first form,
then you'll have to use JavaScript to hide/show the second form.
Personally, I'd use jQuery/jQuery UI to get a date picker on the first
text box, then after a date is entered, display the second box.

Toby


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