[Zope] How to require an @ symbol in email form field??

Duncan Booth duncan@rcp.co.uk
Tue, 18 Jul 2000 16:55:29 +0000


> Is there a way to require at least an "@" sign in the email field? The
> powers that be think this would be useful.
<dtml-unless "'@' in REQUEST.email">... complain here ...</dtml-
unless>

> 
> Here's the form processing code as it stands today. Any help is
> appreciated.
Use javascript to check that all required fields are present before 
the form is actually submitted. Here is some of the code I use:

<SCRIPT Language="Javascript1.2" src="jsvalidate"></SCRIPT>
<form action="..." method="post" onSubmit="return 
Validate(this);">
</SCRIPT>

where jsvalidate is a DTMLDocument that may be found at 
http://www.zope.com/members/Duncan/jsvalidate.

Also, consider using the :default modifier on fields to force them to 
have a value. For example, if you put
<input type="hidden" name="field1:default" value="whatever">

then if the field is left empty, or in the case of a radio button not 
selected, the default value will be used.

> <!-- Check whether any fields are missing. -->
... code snipped ...

Here's a somewhat shorter, albeit more obscure, way to check 
whether all the fields you want are in the REQUEST form:

<dtml-let required="[ 'name', 'email' ]"
   present="_.reorder(REQUEST.form.keys(), with=required)"
   missing="_.reorder(required, without=present)">
<dtml-if missing>
Missing fields:
 <dtml-in missing><dtml-var sequence-item> </dtml-in><br>
<dtml-else>
  ... insert code here ...
</dtml-if>
</dtml-let>


-- 
Duncan Booth                                             duncan@dales.rmplc.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?
http://dales.rmplc.co.uk/Duncan