[eluser]Wackton[/eluser]
I'm working on a little project. I'm a total noob in PHP, that's why I chose CI. It's very nice and well documented.
- I've been reading the Form Validation article, and I decided to use a separate file called "form_validation" to process my form's rules. However, I want to add a callback for my email field. I tried duplicating it just the like username callback, but it doesn't work. Furthermore, since I decided to use the form_validation.php file, I cannot figure out how to add the callback function to it.
Basically put, how do I make a callback function to disallow the word "hotmail" in my email field?
Here's my form_validation.php code:
Code:
<?php
$config = array(
array(
'field' => 'username',
'label' => 'Username',
'rules' => 'trim|required|min_length[5]|max_length[20]|xss_clean'
),
array(
'field' => 'password',
'label' => 'Password',
'rules' => 'trim|required|matches[passconf]|min_length[10]|max_length[25]|md5'
),
array(
'field' => 'passconf',
'label' => 'Password Confirmation',
'rules' => 'trim|required|matches[passconf]'
),
array(
'field' => 'email',
'label' => 'Email',
'rules' => 'trim|required|valid_email'
)
);
?>
How would I add:
Code:
Function email_check($str)
{
if ($str == 'hotmail')
{
$this->form_validation->set_message('email_check', 'The %s field can not be the word "hotmail"');
to the validation file? Thanks in advance, I really like CI!!
Here's my form.php file in case you need it:
Code:
<?php
class Form extends Controller {
function index()
{
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
if ($this->form_validation->run() == FALSE)
{
$this->load->view('myform');
}
else
{
$this->load->view('formsuccess');
}
}
}
?>
It someone could led me a virtual hand, I'd be very grateful. Thanks again..