[turba] Fwd: Turba Add Form

Chuck Hagenbuch chuck@horde.org
Fri, 13 Sep 2002 11:59:10 -0400


Personally, I'd rather add FormSprocket validation to fields so it gets done
server-side as well if we're going to do this...

----- Forwarded message from c.green@mailbox.uq.edu.au -----
    Date: Fri, 13 Sep 2002 12:48:28 +1000
    From: c.green@mailbox.uq.edu.au
Reply-To: c.green@mailbox.uq.edu.au
 Subject: Turba Add Form
      To: chuck@horde.org

Hey Chuck,

Just wrote this bit of javascript to allow forms to be checked for required
attributes in turba.  Thought it might be useful for add.inc and edit.inc etc.

For the user, in the turba/config/attributes.php file you simply add a boolean
value 'required' for each element.

eg...

$attributes['sn'] = array(
    'type' => 'text',
    'required' => true,
    'desc' => _("Family Name")
);

turba/templates/add/add.inc
diff -r1.1 add.inc
1c1,30
< <form name="add_object" action="<?=
Horde::applicationUrl('addobjectaction.php') ?>" method="post">
---
> <script language="Javascript">
>       var required = new Array();
> 
> <?php
>       foreach ($attributes as $key => $field) {
>               if ($key == "name") {
>                       continue;
>               }
> 
>               if ($field['required']) {
>                       print "required['$key'] = '" . $field['desc'] . "';\n";
>               }
>       }
> 
> ?>
> 
>       function validate_form(form) {
>               for (field in required) {
>                       var value = eval('form.elements["object[' + field +
']"].value');
>                       if (value == '') {
>                               alert('The ' + required[field] + ' field is
required');
>                               return false;
>                       }
>                       
>               }
>               return true;
>       }
> 
> </script>
> <form name="add_object" action="<?=
Horde::applicationUrl('addobjectaction.php') ?>" onsubmit="return
validate_form(this)" method="post">

Cheerio,

Cameron Green

-------------------------------------------------
This mail sent through IMP: http://horde.org/imp/

----- End forwarded message -----


-chuck

--
Charles Hagenbuch, <chuck@horde.org>
"After a few minutes the most aromatic and nice smelling Italian coffee 
 will come out of the exhaustpipe." - Our stove-top espresso pot