How to require an @ symbol in email form field??
Hello, I am new to Zope; since our webmaster left I'm trying to make small changes to the website. We have a standard registration form that collects information from users (first name, last name, email, company name, etc.) All of the fields are required, except address 2, address3. Great. fine. If the user doesn't fill out a field, they get an alert. But they can fill each field out with gibberish--as long as there is a character in the input, we accept it. Is there a way to require at least an "@" sign in the email field? The powers that be think this would be useful. Here's the form processing code as it stands today. Any help is appreciated. Sformby <!-- Check whether any fields are missing. --> <dtml-in required> <dtml-comment> The length of the following expr is due to the fact that some types of form elements (e.g. text) always create a var, while others (e.g. radio) don't. </dtml-comment> <dtml-unless expr="REQUEST.form.has_key(_['sequence-key']) and REQUEST.form[_['sequence-key']]"> <dtml-call request.set(missing_fields1)"> </dtml-unless> </dtml-in> <!-- If fields are missing, inform the user. --> <dtml-if request.has_key(missing_fields')"> The following input fields are required and have not been filled out: <!-- List missing fields. --> <ul> <dtml-in required> <dtml-unless expr="REQUEST.form.has_key(_['sequence-key']) and REQUEST.form[_['sequence-key']]"> <li><dtml-var sequence-item> </dtml-unless> </dtml-in> </ul> Please click on your browser's "Back" button to update your information, or <a href="registration.html">click here</a> to start over. <dtml-else>
The nicest way would be to use a JavaScript clientside script on the form page. I think you can find a good one @ javascript.internet.com If you don't want to use Javascript, you can use the regular expression found from the javascript and use it in a python method of module. ----- Original Message ----- From: Stacy Formby <sformby@scicomp.com> To: <zope@zope.org> Sent: Monday, July 17, 2000 7:57 PM Subject: [Zope] How to require an @ symbol in email form field??
Hello,
I am new to Zope; since our webmaster left I'm trying to make small changes to the website. We have a standard registration form that collects information from users (first name, last name, email, company name, etc.) All of the fields are required, except address 2, address3.
Great. fine. If the user doesn't fill out a field, they get an alert. But they can fill each field out with gibberish--as long as there is a character in the input, we accept it.
Is there a way to require at least an "@" sign in the email field? The powers that be think this would be useful.
Here's the form processing code as it stands today. Any help is appreciated.
Sformby
<!-- Check whether any fields are missing. --> <dtml-in required> <dtml-comment> The length of the following expr is due to the fact that some types of form elements (e.g. text) always create a var, while others (e.g. radio) don't. </dtml-comment>
<dtml-unless expr="REQUEST.form.has_key(_['sequence-key']) and REQUEST.form[_['sequence-key']]"> <dtml-call request.set(missing_fields1)"> </dtml-unless> </dtml-in>
<!-- If fields are missing, inform the user. --> <dtml-if request.has_key(missing_fields')"> The following input fields are required and have not been filled out: <!-- List missing fields. --> <ul> <dtml-in required> <dtml-unless expr="REQUEST.form.has_key(_['sequence-key']) and REQUEST.form[_['sequence-key']]"> <li><dtml-var sequence-item> </dtml-unless> </dtml-in> </ul> Please click on your browser's "Back" button to update your information, or <a href="registration.html">click here</a> to start over. <dtml-else>
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
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
On Tue, 18 Jul 2000, Duncan Booth wrote:
Use javascript to check that all required fields are present before the form is actually submitted. Here is some of the code I use:
Note, however, that using Javascript to do the checking client side is only useful as a user convenience. If you have data validation issues you *must* repeat the validation server side, in case some clever cracker^h^h^h^h^h^h^huser bypasses your form and submits data without going through the javascript. --RDM
participants (4)
-
Duncan Booth -
Peter Be -
R. David Murray -
Stacy Formby