Re: [PHP] Re: php and dynamic forms
On Tue, 2006-08-15 at 01:24 -0400, Robert Cummings wrote: On Tue, 2006-08-15 at 13:02 +0800, Bigmark wrote: Does anyone have a simple example script. In the first form include a hidden field that identifies the form when you are checking the post values after submission. This way you know exactly what form was submitted. Second if the first form has been submitted then you know that you need to present the second form also. THe second form should also have a hidden field so that it may be identified upon submission. In this way you can detect which form was submitted (submit buttons are problematic for determining which form was submitted). Then when you detect that the second form was submitted you can handle it's data as you please and then only present the first form. A basic example follows (completely unchecked for typos/errors): And of course it had errors :) See below... ?php $submittedForm = null; if( isset( $_POST['formSubmitted'] ) ) { $submittedForm = $_POST['formSubmitted']; if( $_POST['formSubmitted'] == 'form1' ) { // do something with its data. } else if( $_POST['formSubmitted'] == 'form2' ) { // do something with its data. } } ? form name=form1 method=post action=?= $_SERVER['PHP_SELF'] ? input type=hidden value=form1 / Should be: input type=hidden name=formSubmitted value=form1 / select name=game option value=11/option option value=22/option option value=33/option option value=../option /select input type=submit name=continue value=Continue / /form ?php if( $submittedForm == 'form1' ) { ? form name=form2 method=post action=?= $_SERVER['PHP_SELF'] ? input type=hidden value=form2 / Should be: input type=hidden name=formSubmitted value=form2 / select name=blah option value=fooFoo/option option value=feeFee/option option value=fiiFii/option option value=fohFoh/option option value=fumFum/option /select input type=submit name=continue value=Continue / /form ?php } ? Cheers, Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: php and dynamic forms
On Tue, 2006-08-15 at 13:02 +0800, Bigmark wrote: Does anyone have a simple example script. In the first form include a hidden field that identifies the form when you are checking the post values after submission. This way you know exactly what form was submitted. Second if the first form has been submitted then you know that you need to present the second form also. THe second form should also have a hidden field so that it may be identified upon submission. In this way you can detect which form was submitted (submit buttons are problematic for determining which form was submitted). Then when you detect that the second form was submitted you can handle it's data as you please and then only present the first form. A basic example follows (completely unchecked for typos/errors): ?php $submittedForm = null; if( isset( $_POST['formSubmitted'] ) ) { $submittedForm = $_POST['formSubmitted']; if( $_POST['formSubmitted'] == 'form1' ) { // do something with its data. } else if( $_POST['formSubmitted'] == 'form2' ) { // do something with its data. } } ? form name=form1 method=post action=?= $_SERVER['PHP_SELF'] ? input type=hidden value=form1 / select name=game option value=11/option option value=22/option option value=33/option option value=../option /select input type=submit name=continue value=Continue / /form ?php if( $submittedForm == 'form1' ) { ? form name=form2 method=post action=?= $_SERVER['PHP_SELF'] ? input type=hidden value=form2 / select name=blah option value=fooFoo/option option value=feeFee/option option value=fiiFii/option option value=fohFoh/option option value=fumFum/option /select input type=submit name=continue value=Continue / /form ?php } ? Cheers, Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: php and dynamic forms
At 1:24 AM -0400 8/15/06, Robert Cummings wrote: On Tue, 2006-08-15 at 13:02 +0800, Bigmark wrote: Does anyone have a simple example script. In the first form include a hidden field that identifies the form when you are checking the post values after submission. This way you know exactly what form was submitted. Second if the first form has been submitted then you know that you need to present the second form also. THe second form should also have a hidden field so that it may be identified upon submission. In this way you can detect which form was submitted (submit buttons are problematic for determining which form was submitted). Then when you detect that the second form was submitted you can handle it's data as you please and then only present the first form. A basic example follows (completely unchecked for typos/errors): -snip- Rob's most excellent code. To expand, one could also run the self referencing loop through a switch statement controlled by the hidden value and have as many forms as you wanted. I do this all the time. tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: php and dynamic forms
Does anyone have a simple example script. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php