Welcome Guest, Not a member yet? Register   Sign In
SOLVED - Help with Ion Auth and Validation Please
#1

[eluser]TerryT[/eluser]
Still a CI rookie. I want to pass some data to a view, but struggling with validation and figuring out how my input form is actually opened.

The Users Form lists the Users for a particular Admin and has a button to enable creating a new user under that Admin.

The button calls the Ion Auth controller, create_user method.

The Ion Auth controller has been modified to include validation. The Create User form is opened and I can't figure out where. I now want to pass some data to that Create User form for a multi-select dropdown and I can't find a $this->load->view calling the form. Looked in the User Guide and forum search. Can anyone tell me how the view is called so I can pass it some data?

Any help appreciated. Thanks.

Terry

SOLUTION - In the Auth.php file, create_user method, the line: if ($this->form_validation->run() == true) is actually false the first time through and the form is then called at the very bottom of the method. This is different than most examples where the typical format is if ($this->form_validation->run() == false) then load the view.

Here's the partial code:

Users Form with a button to allow creating new members:

Code:
<br />

&lt;input type=button value="Add New User" class="buttonAdmin"&gt;
</div>

<p>&lt;?php echo $links;?&gt;</p>


Auth.php - Modified Ion Auth Controller

Code:
function create_user()
{
  $id = intval($this->session->userdata('id'));  //Get id from session.
  $data['projects'] = $this->projects_model->get_my_projects_names($id); //added 10/31/11 twt to get admin's projects to add to create_user form in listbox

  if (!$this->ion_auth->logged_in() || !$this->ion_auth->is_admin())
   redirect('auth', 'refresh');

  //validate form input
  $this->form_validation->set_rules('first_name', 'First Name', 'required|xss_clean');
  $this->form_validation->set_rules('last_name', 'Last Name', 'required|xss_clean');
  $this->form_validation->set_rules('email', 'Email Address', 'required|valid_email');
  $this->form_validation->set_rules('phone1', 'First Part of Phone', 'required|xss_clean|min_length[3]|max_length[3]');
  $this->form_validation->set_rules('phone2', 'Second Part of Phone', 'required|xss_clean|min_length[3]|max_length[3]');
  $this->form_validation->set_rules('phone3', 'Third Part of Phone', 'required|xss_clean|min_length[4]|max_length[4]');
  $this->form_validation->set_rules('company', 'Company Name', 'required|xss_clean');
  $this->form_validation->set_rules('password', 'Password', 'required|min_length[' . $this->config->item('min_password_length', 'ion_auth') . ']|max_length[' . $this->config->item('max_password_length', 'ion_auth') . ']|matches[password_confirm]');
  $this->form_validation->set_rules('password_confirm', 'Password Confirmation', 'required');

  if ($this->form_validation->run() == true)
  {
   $username = strtolower($this->input->post('first_name')) . ' ' . strtolower($this->input->post('last_name'));
   $email = $this->input->post('email');
   $password = $this->input->post('password');

   $additional_data = array('first_name' => $this->input->post('first_name'),
    'last_name' => $this->input->post('last_name'),
    'company' => $this->input->post('company'),
    'phone' => $this->input->post('phone1') . '-' . $this->input->post('phone2') . '-' . $this->input->post('phone3'),
   );
  }
  if ($this->form_validation->run() == true && $this->ion_auth->register($username, $password, $email, $additional_data)) //in ion_auth model line 564 $groups is added. It is an array with the groups.
  {
   //check to see if we are creating the user
   //redirect them back to the admin page
   $this->session->set_flashdata('message', "User Created");
   redirect("auth", 'refresh');


Create User Input form that called when button on User form pressed:

Code:
<div class='mainInfo'>

<h1>Create User</h1>
<p>Please enter the users information below.</p>

<div id="infoMessage">&lt;?php echo $message;?&gt;</div>

      &lt;?php echo form_open("auth/create_user");?&gt;

      <p>First Name:<br />
      &lt;?php echo form_input($first_name);?&gt;
      </p>
      
      <p>Last Name:<br />
      &lt;?php echo form_input($last_name);?&gt;
      </p>
      
      <p>Company Name:<br />
      &lt;?php echo form_input($company);?&gt;
      </p>
      
      <p>Email:<br />
      &lt;?php echo form_input($email);?&gt;
      </p>
      
      <p>Phone:<br />
      &lt;?php echo form_input($phone1);?&gt;-&lt;?php echo form_input($phone2);?&gt;-&lt;?php echo form_input($phone3);?&gt;
      </p>
      
      <p>Password:<br />
      &lt;?php echo form_input($password);?&gt;</p>
   <p>(Must be minimum of 8 characters.)</p>
      
      <p>Confirm Password:<br />
      &lt;?php echo form_input($password_confirm);?&gt;
      </p>
  

      &lt;?php echo form_multiselect('projects[]', $projects, set_value('Projects', $projects)); ?&gt;;  
  
      <p>&lt;?php echo form_submit('submit', 'Create User');?&gt;</p>

      
    &lt;?php echo form_close();?&gt;

</div>





Theme © iAndrew 2016 - Forum software by © MyBB