[drupal-devel] Rewriting use of forms in Drupal

Adrian Rossouw adrian at bryght.com
Fri Jun 3 19:29:05 UTC 2005


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 03 Jun 2005, at 6:17 PM, Nedjo Rogers wrote:

>> Only in form() itself we'd generate the html. form() should be a
>> themable function.
>>
>
> A great step forward--better control, more flexibility.  Anything  
> that moves us away from hard-coded HTML generation and toward  
> separation of content and presentation is a good thing.
>
> The "weight" parameter suggestion sounds good.  I've often been  
> frustrated at not having control over the order of form elements  
> (e.g., not being able to insert new elements at a specified place).
>
Furthermore, we should look at the admin section. We have tables  
containing inputs. Should we break the new method of seperating things
and just use form_element(array()) , and how do we handle the <form>  
tag ?

What I think should happen is we should create all the form elements,  
and then hand it over to a themeing function that generates the table,
which leads me to think we might need to have element types for  
labels and images too (thinking of  the theme selection screen). Perhaps
a generic 'markup', or 'html' will suffice.

Also, what I have planned would mean that each form has a unique  
name... which leaves us with the interesting thought that we could
have a hook_actions() which allows us to set a callback for the form.

IE:
function module_actions() {
     $actions = array(
         'module_form' => array('callback' => 'module_formname',  
'access' => user_access('add some thing'))
    );
    return $actions;
}

Then your form definition is as follows :

function module_formname($action, $op, $edit = array()) {
     switch ($op) {
         case 'elements' :
              /* Define elements array here */
              break;
         case 'validate' :
             /* Validate form here. */
             return $valid;
             break;
        case 'execute' :
             /*sql or whatever goes here */
             break;
     }
}

What does this mean to us ?

It means that you can place any form anywhere simply using form('form  
name here'), it
could even be possible to have multiple forms in the same <form> tag  
using form(array('form1', 'form2'));

It would be possible too execute any action, whatsoever, from  
wherever (with the permission being checked on
the action.)

Furthermore, we could have a generic formapi to handle parts of  
nodeapi. This would mean you can add and
remove fields from any form, including nodes, comments, admin screens  
(this could be great for people who
want to generate their own admin pages).

Done right, it could essentially be similar to the theme()  
functionality, but for all forms/actions.


- --
Adrian Rossouw
Drupal developer and Bryght Guy
http://drupal.org | http://bryght.com


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (Darwin)

iD8DBQFCoK/ggegMqdGlkasRAmBfAJ4p3fcCM8V04IRPoG4lDw5X5GK3VQCcCFYW
HTcisJmdRtd/hdOanFkgyic=
=Yl8W
-----END PGP SIGNATURE-----



More information about the drupal-devel mailing list