Welcome Guest, Not a member yet? Register   Sign In
Callbacks
#1

[eluser]aeternuslibertas[/eluser]
Hi How is everyone doing!?

my question is with regard to callbacks...
I was writing an application and wanted to check a user sign up for duplicate emails, just like this thread
http://ellislab.com/forums/viewthread/168921/

my question is... how does the function, email_unique know to take the input value from the email field in the form into the parameter $str
is it because of the
Code:
$this->form_validation->set_rules('email', 'Email', 'required|callback_email_unique');
LINE?
Code:
function email_unique($str)
    {
        // Note that there are 100 of different ways to create this SQL,
        // so do it your own way.
        $result = $this->db->get_where('table_name', array('email' => $str));

        // Is there a row with this email?
        if ($result->num_rows > 0)
        {
            // Let's return false for the validation and set a custom message for this function
            $this->form_validation->set_message('email_unique', 'That email is already used.');
            return FALSE;
        }
        else
        {
            // Everything is good, don't return an error.
            return TRUE;
        }
    }

my approach looks something like this...

Code:
function email_unique()
    {
        //NEW LINE
       $email=$this->input->post('email');
        // Note that there are 100 of different ways to create this SQL,
        // so do it your own way.
        $result = $this->db->get_where('table_name', array('email' => $email));

        // Is there a row with this email?
        if ($result->num_rows > 0)
        {
            // Let's return false for the validation and set a custom message for this function
            $this->form_validation->set_message('email_unique', 'That email is already used.');
            return FALSE;
        }
        else
        {
            // Everything is good, don't return an error.
            return TRUE;
        }
    }

does it make a difference if i keep the
Code:
$str
parameter or use the
Code:
$email=$this->input->post('email');
line?


Messages In This Thread
Callbacks - by El Forum - 06-09-2011, 04:36 PM
Callbacks - by El Forum - 06-09-2011, 07:09 PM
Callbacks - by El Forum - 06-09-2011, 08:30 PM
Callbacks - by El Forum - 06-09-2011, 11:01 PM
Callbacks - by El Forum - 06-12-2011, 05:28 PM



Theme © iAndrew 2016 - Forum software by © MyBB