[eluser]joshsmith[/eluser]
Hey i am currently building a registration form. I am up to the e-mail part but its not working correctly as of now. I have added both of my function (both on controller 'User'). When i echo out the e-mail string i get a error on line 49. anyone know why this is not working?
Line 49
Code: echo 'Click the link below to activate your account' . anchor('http://localhost/codetwo/index.php/user/random_string/' . $activation_code,'Confirmation Register';
Code: function register(){
$this->load->library('form_validation');
$this->form_validation->set_rules('username', 'Username', 'required|min_length[5]|max_length[12]|xss_clean|callback_dbcheck');
$this->form_validation->set_rules('name', 'Name', 'required|min_length[3]|max_length[20]|xss_clean');
$this->form_validation->set_rules('email', 'E-mail', 'required|min_length[3]|max_length[20]|xss_clean|valid_email');
$this->form_validation->set_rules('password', 'Password', 'required|min_length[3]|max_length[20]|xss_clean');
$this->form_validation->set_rules('password_conf', 'Re-type Password', 'required|min_length[3]|max_length[20]|xss_clean|matches[password]');
if ($this->form_validation->run() == FALSE) {
$this->load->view('viewregister');
}
else {
$username = $this->input->post('username');
$name = $this->input->post ('name');
$email = $this->input->post ('email');
$password = $this->input->post ('password');
$activation_code = $this->random_string(10);
$this->Usermodel->register_user($username,$name, $email, $password, $activation_code);
// send e-mail verification
$this->load-library('email');
$this->email->from('[email protected]', 'al');
$this->email->to();
$this->email->subject('Registration Confirmation');
$this->email->message('Click the link below to activate your account' . anchor('http://localhost/codetwo/index.php/user/confirmation_activation/' . $activation_code,'Confirmation Register'));
echo 'Click the link below to activate your account' . anchor('http://localhost/codetwo/index.php/user/random_string/' . $activation_code,'Confirmation Register';
// echo " you have been registered $username";
}
}
Code: function random_string() {
$chars = "abcdefghijklmnopqrstuvwxyz0123456789";
srand((double)microtime()*1000000);
$i = 0;
$pass = '';
while ($i <= 7) {
$num = rand() % 33;
$tmp = substr($chars, $num, 1);
$pass = $pass .$tmp;
$i++;
}
return $activation_code;
}
[eluser]isawhat[/eluser]
You forgot the ) at the end of the anchor tag.
[eluser]joshsmith[/eluser]
good eye, ok i made the change but i get a different error on line 43
Line 43
Code: $this->load-library('email');
[eluser]Bart v B[/eluser]
i am not sure but $this->email->to(); is empty.
Must that not be something like?
Code: $this->email->to($email);
[eluser]joshsmith[/eluser]
it should, but i left it blank just in case that triggers a error. Like at the moment that does not get send to a e-mail. i am just echo the line out to see if it works first before adding in the e-mail.
[eluser]isawhat[/eluser]
On line 43 your missing the > after load
Code: $this->load->library('email');
[eluser]joshsmith[/eluser]
ah perfect, now it shows. I got one more error on line 86. Due to this error i don't see the activation_code in my url.
line 86
Code: return $activation_code;
--> in random_string function
Controller
Code: function register(){
$this->load->library('form_validation');
$this->form_validation->set_rules('username', 'Username', 'required|min_length[5]|max_length[12]|xss_clean|callback_dbcheck');
$this->form_validation->set_rules('name', 'Name', 'required|min_length[3]|max_length[20]|xss_clean');
$this->form_validation->set_rules('email', 'E-mail', 'required|min_length[3]|max_length[20]|xss_clean|valid_email');
$this->form_validation->set_rules('password', 'Password', 'required|min_length[3]|max_length[20]|xss_clean');
$this->form_validation->set_rules('password_conf', 'Re-type Password', 'required|min_length[3]|max_length[20]|xss_clean|matches[password]');
if ($this->form_validation->run() == FALSE) {
$this->load->view('viewregister');
}
else {
$username = $this->input->post('username');
$name = $this->input->post ('name');
$email = $this->input->post ('email');
$password = $this->input->post ('password');
$activation_code = $this->random_string(10);
$this->Usermodel->register_user($username,$name, $email, $password, $activation_code);
// send e-mail verification
$this->load->library('email');
$this->email->from('[email protected]', 'al');
$this->email->to($email);
$this->email->subject('Registration Confirmation');
$this->email->message('Click the link below to activate your account' . anchor('http://localhost/codetwo/index.php/user/confirmation_activation/' . $activation_code,'Confirmation Register'));
//$this->email->send();
echo 'Click the link below to activate your account' . anchor('http://localhost/codetwo/index.php/user/random_string/' . $activation_code,'Confirmation Register');
// echo " you have been registered $username";
}
}
function dbcheck ($username) {
$checkusername = array('username' => $username);
$verifyusername = $this->db->get_where('tbregister', $checkusername);
//$this->db->where('username', $username);
//$verifyusername = $this->db->get('tbregister');
if ($verifyusername->num_rows() > 0) {
$this->form_validation->set_message('dbcheck','Please choose a different Username as it is already taken');
return FALSE;
}
else {
return TRUE;
}
}
function random_string() {
$chars = "abcdefghijklmnopqrstuvwxyz0123456789";
srand((double)microtime()*1000000);
$i = 0;
$pass = '';
while ($i <= 7) {
$num = rand() % 33;
$tmp = substr($chars, $num, 1);
$pass = $pass .$tmp;
$i++;
}
return $activation_code;
}
[eluser]isawhat[/eluser]
You don't define $activation_code, so nothing is returned.
[eluser]echo sara[/eluser]
no, the output of random_string defines it. its the scrambled letter/number.
Code: function random_string() {
$chars = "abcdefghijklmnopqrstuvwxyz0123456789";
srand((double)microtime()*1000000);
$i = 0;
$pass = '';
while ($i <= 7) {
$num = rand() % 33;
$tmp = substr($chars, $num, 1);
$pass = $pass .$tmp;
$i++;
}
return $activation_code;
}
[eluser]scottwire[/eluser]
$activation_code doesn't exist until it gets the return value of random_string(). You need to return $pass
Code: function random_string() {
$chars = "abcdefghijklmnopqrstuvwxyz0123456789";
srand((double)microtime()*1000000);
$i = 0;
$pass = '';
while ($i <= 7) {
$num = rand() % 33;
$tmp = substr($chars, $num, 1);
$pass = $pass .$tmp;
$i++;
}
return $pass;
}
|