On Mon, 1 Jun 2009 12:53:31 +1000, angusm...@pobox.com ("Angus Mann") wrote:

>Hi all. I realize this is more an HTML question than PHP but I'm sure someone 
>here can help.
>
>I have several forms with lots (dozens) of text inputs. If the user presses 
>the "Update" button I want the form handled by "update.php" but if they press 
>"Delete" it needs to be handled by "delete.php" or "add.php" and so-on 
>depending on the button they press.
>
>But when establishing the form I can only have <form method="POST" 
>action="delete.php"> or "add.php" or whatever.
>
>Is there a way to direct the content of the form do a different handler 
>depending on the button?
>
>I know I can use javascript to direct to a constructed URL and append 
>?name=smith&address=hishouse&telephone=28376.....and so on but this is not 
>practical when there are dozens of entries....the URL becomes massive. I 
>prefer to use "POST" and then use PHP to extract the POST array.
>
>Any ideas?

I have two ways of handling this type of menu. In the first I have a form with 
a 'submit'
button, containing a number of radio buttons specifying different actions: 

<p><input type = "radio" name = "action" value = "sln" <?php if ($action == 
'sln') { echo
(' checked ') ; } if (!$valid) { echo 'disabled'; } ?>/> Select names</p>

The form can also contain check buttons specifying auxiliary options and text 
boxes
specifying input quantities.

My second type of menu looks very similar, but there is no form, and each 
option is a
small image (usually a yellow diamond). When you hit any button it invokes a 
new page
passing the new action, and related quantities, as parameters:

echo'<p><a 
href="'.$home_page.'?action=edit_datfile&amp;item='.$item.'&amp;edit=2"><img 
src="Images/19_13_di_y.gif" width="19" height="13" border="0" alt="Edit 
item"></a>';
echo ' Edit album page</p>';

The same response handler handles both types of menu. It first looks for 
'action' in
$_GET, then it looks in $_POST, then it loads the appropriate handler as 
described below.

My standard program operates in four steps:

1. It checks for responses from the preceding page 

2. It processes them. To do this it has a table of response handlers, and 
includes a file
which handles the responses from the previous action.

3. It reads the new action, and includes the handler for this from a table of 
action
handlers. Quite often this is another menu which enables the user to specify 
additional
information. It is usually (but not necessarily) included inside the form for 
the main
menu, so that the specific fields appear above the normal foot. 

4. Finally it offers the same, or a different, menu for the user to specify the 
next
action. 

The advantage of the first type of menu is that it permits you to specify 
several
different values at the same time. For example one menu has a text input in 
which you can
enter a search string and different action buttons enabling you to specify to 
search
surnames only, search any name, or search in all possible fields. Its 
disadvantage is that
you have to select an action, then hit the submit button.

The advantage of the second type is that you only have to click one button, and 
it's
disadvantages are that you cannot specify auxiliary quantities, and you don't 
get a second
chance. 

Because the program is broken up in this way it is extremely flexible, and can 
completely
change its appearance and behaviour according to the task it is carrying out. 
The whole
program has a massive amount of code, but most of this is in the action and 
response
handlers, and because these are only included when they are needed, only a 
relatively
small amount of code is in memory at any given time.


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

Reply via email to