function save_user($firstname, $lastname, $email, $password) { $ci =& get_instance(); $ci->load->model('user_m'); //echo $ci->input->post('ajax'); $firstname = $ci->input->post('fname') != '' ? $ci->input->post('fname') : $firstname; $lastname = $ci->input->post('lname') != '' ? $ci->input->post('lname') : $lastname; $email = $ci->input->post('email') != '' ? $ci->input->post('email') : $email; $password = $ci->input->post('password') != '' ? $ci->input->post('password') : $password; $usertype = $ci->input->post('usertype') != '' ? $ci->input->post('usertype') : '4'; $ci->form_validation->set_rules($ci->user_m->add_user_validation); $str = ''; if ($ci->form_validation->run() == FALSE) { //if there were errors add them to the errors array echo error_template(validation_errors()); } else { $user_data = array('fname' => $firstname, 'lname' => $lastname, 'email' => $email, 'usertype' => $usertype, 'password' => md5($password), 'dateadded' => mysqldate(), 'slug' => now() . random_string('numeric', 8)); //more validation special cases if ($ci->input->post('cpassword') != '') { //chek o see id the two match if ($ci->input->post('password') != $ci->input->post('cpassword')) { echo error_template('Passwords do not match'); } } else { $user_id = $ci->user_m->create($user_data); if ($user_id) { //add him to the roles tables //if online if (check_live_server()) { //send email to user $salutation = $content = '<p>Hello<strong> ' . ucwords($firstname . ' ' . $lastname) . '</strong>,</p>'; $content = '<p>Hello<strong> ' . ucwords($firstname . ' ' . $lastname) . '</strong>,</p> <p>You have created a new account on <a href="' . base_url() . '>' . base_url() . '</a>.</p> <p>Below are your login credentials:</p> <p><strong>Username</strong>: ' . $email . '</p> <p><strong>Password</strong>: ' . $password . '</p> <p>Click <a href="' . base_url() . 'admin/login">here</a> to login</p> '; send_html_email($ci->input->post('email'), 'New account', $salutation, $content, SITE_EMAIL); } //if there were errors add them to the errors array $str .= jquery_clear_fields(); echo $str; return $user_id; } else { //if there were errors add them to the errors array echo warning_template('User was not added. Please try one more time'); } } } }
<?php if (isset($errors)) { echo error_template($errors); } elseif (isset($success)) { echo success_template($success); echo jquery_clear_fields(); } ?> <form action="<?= current_url() ?>" class="form-horizontal" method="post"> <div class="form-group"> <div class="col-md-12"> <input type="text" name="fname" value="<?= set_value('fname') ?>" id="firstname" class="form-control" placeholder="firstname"/> </div> </div> <div class="form-group"> <div class="col-md-12"> <input type="text" name="lname" value="<?= set_value('lname') ?>" id="lastname" class="form-control" placeholder="lastname"/> </div> </div> <div class="form-group"> <div class="col-md-12"> <input type="email" name="email" value="<?= set_value('email') ?>" id="email" class="form-control" placeholder="email address"/>