name    = u""
email   = u""
phone   = u""
workplace   = u""
title   = u""

## Check that the anti-spam honeypot information looks ok, and get the mappings between the obfuscated 
## fieldnames and the real fieldnames.
(honeypots,formErrorMsg) = context.checkHoneyPots( context,  ("attendeename","attendeeemail","attendeeworkplace","attendeephone","attendeetitle",) )

if formErrorMsg:
    ## This looks like a spam-bot, so we can skip the rest of the checks.
    errors.append(formErrorMsg)
else:
    ## Get the values of the form fields that contain the actual user-entered data.
    name    = html2text(    context.REQUEST[honeypots['fieldname2hashedfieldname']["attendeename"]])
    email   = html2text(    context.REQUEST[honeypots['fieldname2hashedfieldname']["attendeeemail"]])
    phone   = html2text(    context.REQUEST[honeypots['fieldname2hashedfieldname']["attendeephone"]])
    workplace   = html2text(    context.REQUEST[honeypots['fieldname2hashedfieldname']["attendeeworkplace"]])
    title   = html2text(    context.REQUEST[honeypots['fieldname2hashedfieldname']["attendeetitle"]])
    
    ## Check that all the required fields are present
    for visibleFieldName,maxsize,fieldvalue in ( ("Navn",          100,  name),
                                                 ("Epostadresse",  255,  email),
                                                 ("Telefon",  100,  phone),
                                                 ("Tittel",  100,  title),
                                                 ("Arbeidssted",  100,  workplace),
                                                  ):
        if fieldvalue.strip() == "":
            errors.append( u"""Du må skrive noe i "%s" boksen.""" % (visibleFieldName,))
            
Example #2
0
formErrorMsg = u"" ## This will be set to a user-readable error-message if the form contains an error.
name    = u""
email   = u""
heading = u""
comment = u""

## Check that the anti-spam honeypot information looks ok, and get the mappings between the obfuscated 
## fieldnames and the real fieldnames.
(honeypots,formErrorMsg) = context.checkHoneyPots( context,  ("name","email","heading","comment") )

if formErrorMsg:
    ## This looks like a spam-bot, so we can skip the rest of the checks.
    errors.append(formErrorMsg)
else:
    ## Get the values of the form fields that contain the actual user-entered data.
    name    = html2text(    context.REQUEST[honeypots['fieldname2hashedfieldname']["name"]])
    email   = html2text(    context.REQUEST[honeypots['fieldname2hashedfieldname']["email"]])
    heading = html2safehtml(context.REQUEST[honeypots['fieldname2hashedfieldname']['heading']])
    comment = html2safehtml(context.REQUEST[honeypots['fieldname2hashedfieldname']["comment"]])
    
    ## Check that all the required fields are present
    for visibleFieldName,maxsize,fieldvalue in ( ("Navn",          100,  name),
                                                 ("Epostadresse",  255,  email),
                                                 ("Overskrift",     50,  heading),
                                                 ("Kommentar",    1000,  comment) ):
        if fieldvalue.strip() == "":
            errors.append( u"""Du må skrive noe i "%s" boksen.""" % (visibleFieldName,))
            
        
        if len(fieldvalue) > maxsize:
            errors.append(u"""Teksten i "%s" boksen er for lang! Prøv å korte ned teksten litt.""" % (visibleFieldName,))