You start off with a simple contact form in XML. More information about creating this config can be found on my slides about Zend_Form.
<?xml version="1.0" encoding="UTF-8"?>
<forms>
<development>
<contact>
<action>/is/here</action>
<method>post</method>
<name>contactForm</name>
<elements>
<name>
<type>text</type>
<options>
<label>Name</label>
<required>true</required>
</options>
</name>
<email>
<type>text</type>
<options>
<label>Email</label>
<required>true</required>
<validators>
<emailAddress>
<validator>EmailAddress</validator>
</emailAddress>
</validators>
</options>
</email>
<message>
<type>textarea</type>
<options>
<label>Message</label>
<required>true</required>
</options>
</message>
<submit>
<type>submit</type>
<options>
<label>Send</label>
<class>button</class>
</options>
</submit>
</elements>
</contact>
</development>
</forms>
To enable the Zend_Captcha feature within your form, you just add a captcha configuration right before your submit button.
<captcha>
<type>captcha</type>
<options>
<label>Please verify you're a human</label>
<captcha>
<captcha>Image</captcha>
<wordLen>6</wordLen>
<timeout>300</timeout>
<font>../app/data/impact.ttf</font>
</captcha>
</options>
</captcha>The result is then a nice form with a captcha element.

Validation is done through the form validator, so all you need to check is: $form->isValid($_POST);
So, now fight off those unwanted messages in your database or mailbox and use the power of Zend_Form and Zend_Config_Xml for your ease of use and maintainability.








4 comments: