Validating email address with API
Permalink
Hi guys
This is an easy one I'm sure, but the API docs aren't helping me. I'm trying to use the inbuilt validation class to validate an email address.
Here's my code:
The API docs for the email method say this:
but it's not clear to me what $em is. I don't need $testMXRecord I don't think. Anyway, it's not working, even if I feed it blank arguments for those variables.
Any thoughts?
This is an easy one I'm sure, but the API docs aren't helping me. I'm trying to use the inbuilt validation class to validate an email address.
Here's my code:
protected function validate() { $vt = Loader::helper('validation/strings'); if (!$vt->email($this->post('contact_email'))) { $this->error->add(t('Please enter a valid email address')); } }
The API docs for the email method say this:
email (line 31) Validates an email address * access: public bool email ( $em, [ $testMXRecord = false], string $address) * string $address * $em * $testMXRecord
but it's not clear to me what $em is. I don't need $testMXRecord I don't think. Anyway, it's not working, even if I feed it blank arguments for those variables.
Any thoughts?
Thanks Mnkras, but I think the problem might actually relate to a separate issue - I'm trying to validate fields which are intended to become attributes, and looking at the generated source of the page, they all have names like "akID[12][value]" rather than the attribute name, which is what I'm referencing in the PHP. It therefore makes sense that the values which are being validated are empty - they are never set.
Any thoughts on that particular problem? :)
EDIT: I think the problem might relate to the issue discussed in this post:http://www.concrete5.org/community/forums/customizing_c5/rendering-...
Any thoughts on that particular problem? :)
EDIT: I think the problem might relate to the issue discussed in this post:http://www.concrete5.org/community/forums/customizing_c5/rendering-...
so aslong as $this->post('contact_email') is ok it should work, echo it to make sure its the email.