Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2009-03-17 09:20:30

gomedia
Plugin Author
Registered: 2008-06-01
Posts: 1,167
Website

adi_contact – Form field validation, spam prevention & more

Summary

adi_contact provides form field validation, spam prevention, email header/body extras, database update, MailChimp subscription for zem_contact_reborn or zem_contact_reborn v4.5+.

Specifically:

  • submitted field combination check
  • submitted field content validation
  • anti-spam measures
  • database update
  • email header options (CC & BCC)*
  • append lines to email body*
  • MailChimp list subscription*

Once installed, a collection of new tags are available.

Validation & spam detection:

  • adi_contact_combo – define valid combinations of submitted form fields
  • adi_contact_validate – validate the content of submitted form fields
  • adi_contact_spam – block spam in submitted form fields
  • adi_contact_labels – specify labels to be used in error messages
  • adi_contact_checkboxes – to specify which fields are checkboxes
  • adi_contact_javascript – required if zem_contact input/error forms are separate

Email header/body options*:

  • adi_contact_headers – CC and BCC email addresses
  • adi_contact_body – append text to email message

Database update:

  • adi_contact_db – container tag for database updates
  • adi_contact_db_data – defines mapping of contact & database fields, default values etc.

MailChimp list subscription*:

  • adi_contact_mailchimp – container tag for MailChimp list subscription
  • adi_contact_mailchimp_data” – defines mapping of contact & MailChimp fields

*Requires zem_contact_reborn v4.5+.

See the help supplied with the plugin, or have a look online.

Version History

  • 0.6
    • fixed: problem with validate type=“equal” error message
    • enhancement: database update functionality
    • enhancement: MailChimp subscription
    • TXP 4.6 compatibility
    • new tags: adi_contact_headers & adi_contact_body
    • ZCR 4.5+ compatibility: “errorElement” class used in addition to “zemRequirederrorElement”
  • 0.5
    • fixed: javascript doesn’t find contact <form> if zcr input & error forms are separate (thanks jakob)
    • fixed: error message if no fields filled in when using “value” attribute
    • fixed: errors in checkbox processing (thanks jakob)
    • enhancement: extended “name”+“value” dependency to “restrict” & “number” (for jakob)
  • 0.4
    • change: new adi_contact_checkboxes tag (adi_contact_combo ‘checkbox’ attribute withdrawn)
    • enhancement: adi_contact_combo if “value” then “required” (for sacripant)
    • fix: internationalised ‘Yes’ & ‘No’ in checkboxes (thanks sacripant)
    • fix: no more duplicate javascript insertion
    • class action: ‘adi_contact_combo_error’, ‘adi_contact_validate_error’, ‘adi_contact_spam_error’ (for net-carver)
    • new adi_contact_validate type ‘base64’ (for net-carver)
    • javascript code rewrite (& bug fixes: <select>, multiple forms)
  • 0.3
    • enhancement: new adi_contact_validate option type=“equal” (for Kevin Potts)
    • fix: adi_contact_combo now processes an unticked checkbox correctly (as not being a field of interest) (thanks Logoleptic)
    • fix: adi_contact_validate coding error (thanks planeth)
  • 0.2
    • enhancement: new adi_contact_combo attribute ‘required’; equivalent to restrict=“equal” number=“1”, enables custom error messages (inspired by Bloke)
    • enhancement: new adi_contact_validate attribute & option type=“custom” pattern=“pattern” (for Bloke)
    • enhancement: new adi_contact_validate attribute & option type=“url” (inspired by Bloke)
    • enhancement: new adi_contact_spam attribute ‘exclude’ (e.g. use in conjunction with adi_contact_validate type=“url”)
    • fix: adi_contact_combo fails to cope with checkboxes (new attribute ‘checkbox’) (thanks valpc)
  • 0.1.1
    • fix: adi_contact_spam error message field lists incorrectly generated (both standard & custom)
  • 0.1
    • initial release

Download & Installation

Download adi_contact and install the plugin in the usual way.

Use adi_contact tags within a <txp:zem_contact> ... </txp:zem_contact> container.

Bugs & Limitations

  • only works with zem_contact
  • Javascript is used to retrofit error classes to labels & fields, so if it’s switched off you won’t get your lovely red warnings in the right places
  • you must use the name attribute with every zem_contact field – otherwise adi_contact won’t be able to properly identify them
  • if you’re doing something particularly sexy with your zem_contact form, such as tags within tags within tags – i.e. something that causes the parser to do a second pass – then adi_contact will struggle!

Let me know if you find any other problems.

Feedback

Comments are most welcome.

Acknowledgements

jakob sent me some beers for version 0.5 – and most welcome they were too! Thanks.

Bloke has been very patient in guiding me through the new ZCR functionality. It’s much appreciated.

Spread the love

If you find this plugin useful and would like a warm and fuzzy feeling to go with it, please consider donating to the Textpattern development team.

Last edited by gomedia (2016-06-07 02:26:14)

Offline

#2 2009-03-17 10:56:18

jpdupont
Member
From: Virton (BE)
Registered: 2004-10-01
Posts: 590
Website

Re: adi_contact – Form field validation, spam prevention & more

Hi Adi,
Could you give an example of message attribute [NAME], … ? I want to translate the adi_contact_spam messages.

Other idea for your plugin … Is it possible to allow html formatting of the mails zem_contact send ?

Offline

#3 2009-03-17 12:21:01

gomedia
Plugin Author
Registered: 2008-06-01
Posts: 1,167
Website

Re: adi_contact – Form field validation, spam prevention & more

jpdupont wrote:

Could you give an example of message attribute [NAME], … ? I want to translate the adi_contact_spam messages.

Hi JP. Sorry, I meant to provide some examples … and forgot!

In the plugin help there’s an example of a requirement that at least one field out of three must be filled in:

<txp:adi_contact_combo names="likes,dislikes,comments" restrict="min" number="1" />

The standard error message would be something like: At least 1 of “Likes, Dislikes, Comments” required.

If you used the message="" attribute (and apologies for the dodgy French) as follows:

message="Au moins un des [NAMES] est nécessaire."

The message would change to: Au moins un des Likes, Dislikes, Comments est nécessaire.

The error messages for adi_contact_spam should work in a similar manner.

Other idea for your plugin … Is it possible to allow html formatting of the mails zem_contact send?

I had an idea that, possibly, there could be a tag to process fields as Textile – this would output HTML. I haven’t looked if it’s feasible but it is it the sort of thing you mean or do you want the whole email HTML formatted?

Offline

#4 2009-03-17 13:02:05

jpdupont
Member
From: Virton (BE)
Registered: 2004-10-01
Posts: 590
Website

Re: adi_contact – Form field validation, spam prevention & more

Is this code correct : <txp:adi_contact_spam names="Nom,E-mail,Téléphone,Message" message="Possible SPAM détecté dans [NAMES]" /> ?
Nom,E-mail,Téléphone,Message are the labels of the fields like this : <txp:zem_contact_text label="Téléphone" break="" /> .

Offline

#5 2009-03-18 00:08:49

gomedia
Plugin Author
Registered: 2008-06-01
Posts: 1,167
Website

Re: adi_contact – Form field validation, spam prevention & more

JP,

You have to explicitly set the name of each field so that the adi_contact tags can reference them. I didn’t realise you could omit the name attribute but I just tried it & zem_contact will generate a “random” name instead.

So, in your example, the zem_contact tags would have to look something like:

<txp:zem_contact_text name="name" label="Nom" break="" />
<txp:zem_contact_text name="email" label="E-mail" break="" />
<txp:zem_contact_text name="phone" label="Téléphone" break="" />
<txp:zem_contact_textarea name="message" label="Message" break="" />

And the adi_contact_spam tag would then be:

<txp:adi_contact_spam names="name,email,phone,message" message="Possible SPAM détecté dans [NAMES]" />

If you don’t use adi_contact_labels then if a field is blank when the user submits the form, error messages will contain a capitalised version of the name, e.g. “name” would become “Name”.

This would be fine for name="message" but not for the others, so use:

txp:adi_contact_labels name="Nom" email="E-mail" phone="Téléphone" />

It appears a bit of a duplication but it’s the only way I can think of implementing it (ZCR does’t provide a name to label mapping unless a field has been filled in). But it’s not necessarily a bad thing. Image if you had:

name="story" label="Please tell us your life story, in no more than 300 words, giving us names and dates (please leave in all the gory details)"

That label would be a bit over the top to use in an error message!

In the process of checking the message functionality I found a couple of issues which I’ve fixed, so please download version 0.1.1

Offline

#6 2009-03-18 07:01:28

jpdupont
Member
From: Virton (BE)
Registered: 2004-10-01
Posts: 590
Website

Re: adi_contact – Form field validation, spam prevention & more

Thanks Adi ! Works now as expected.

Offline

#7 2009-04-17 18:08:31

valpc
Member
Registered: 2007-03-01
Posts: 18

Re: adi_contact – Form field validation, spam prevention & more

Does this plugin support validation of zem_contact_checkbox? I have 3 checkboxes and I want to ensure that at least one of them is checked. I tried using adi_contact_combo to make at least one required but my form gets submitted without the fields being required.

<txp:zem_contact_checkbox name=“Orange” label=“Orange” required=“0” /> <txp:zem_contact_checkbox name=“Apple” label=“Apple” required=“0” /> <txp:zem_contact_checkbox name=“Bananna” label=“Bananna” required=“0” />

<txp:adi_contact_combo names=“Orange,Apple,Bananna” require=“Orange,Apple,Bananna” restrict=“min” number=“1” />

What am I doing wrong?

Last edited by valpc (2009-04-17 18:13:13)

Offline

#8 2009-04-17 18:14:56

valpc
Member
Registered: 2007-03-01
Posts: 18

Re: adi_contact – Form field validation, spam prevention & more

I modified code to be

<txp:adi_contact_combo names=“Orange,Apple,Bananna” require=“Orange,Apple,Bananna” required=“1” restrict=“min” number=“1” />

and now I cannot submit form ! I keep getting the validation message “Exactly 1 of “Orange, Apple, Bananna” required.” It seems it is all or nothing.

Appreciate any help :)

Offline

#9 2009-04-18 03:49:15

gomedia
Plugin Author
Registered: 2008-06-01
Posts: 1,167
Website

Re: adi_contact – Form field validation, spam prevention & more

valpc wrote:

What am I doing wrong?

Probably nothing! I’ll look into it.

Offline

#10 2009-04-19 09:51:06

gomedia
Plugin Author
Registered: 2008-06-01
Posts: 1,167
Website

Re: adi_contact – Form field validation, spam prevention & more

Version 0.2 now available (valpc, please re-download your copy of 0.2)

Summary

  • enhancement: new adi_contact_combo attribute ‘required’; equivalent to restrict=“equal” number=“1”, enables custom error messages (inspired by Bloke)
  • enhancement: new adi_contact_validate attribute & option type=“custom” pattern=“pattern” (for Bloke)
  • enhancement: new adi_contact_validate attribute & option type=“url” (inspired by Bloke)
  • enhancement: new adi_contact_spam attribute ‘exclude’ (e.g. use in conjunction with adi_contact_validate type=“url”)
  • fix: adi_contact_combo fails to cope with checkboxes (new attribute ‘checkbox’) (thanks valpc)

Offline

Board footer

Powered by FluxBB