PDA

Click to See Complete Forum and Search --> : Multiple forms on one page


nmadd
Apr 24th, 2008, 11:19 AM
I have some very basic knowledge of PHP and that is it.

I'm curious about allowing multiple forms on one page based upon the query string. For example, this very site's profile.php page. Based upon the 'do' query string, a certain form is printed to the page. The user can then fill in the form and submit.

This is as simple as getting the query string value and then printing the necessary form to the page, correct? Then when the form is submitted back to the profile.php page there is a hidden input that shows which form it is? - i.e. on the profile.php editoptions page there is this:
<input type="hidden" name="do" value="updateoptions" />

1)Enough of my babbling, is this the correct logic for something like this?
2)If I am considering doing this with multiple forms that would execute a database query, is there any reason to do it like this or should I just make a separate page for each form?

Well, that was long winded. Thanks for any input or for telling me that I'm not making any sense.

penagate
Apr 24th, 2008, 11:18 PM
(1) vBulletin's 'do' method is not fantastic, because it results in long scripts, and doesn't decouple presentation from logic at all.

If it's available to you, I recommend you use URL rewriting to redirect all requests to a single controller script. This way you can parse the URL yourself and then include whichever script(s) you need to process the request. These scripts can then include whatever script(s) are needed to display the page.

Look up 'MVC architecture' to learn more about decoupling presentation, logic, and data.


(2) Place your data logic in a data layer, such as in a set of scripts that contain database-related code. Then reference this layer from your logic (controller) layer where required.

'Pages', from the perspective of the client, are a virtual concept, and need not relate to anything physical on the server.

nmadd
Apr 25th, 2008, 09:29 AM
Thanks! I'll definitely be researching MVC.

visualAd
Apr 26th, 2008, 07:50 AM
PHP automatically buids arrays if you use square brackets with variable names. So I tend to use this method rather than an extra variable:

<input type="text" name="updateProfile[name]" />


In PHP you can then access the variable as follows:

$_POST['updateProfile']['name']


For get requests; I would however favour having an action variable such as do.