Welcome Guest, Not a member yet? Register   Sign In
Two form on Same Page
#4

[eluser]Michael Wales[/eluser]
Place a unique identifier within each of the forms (I like to use the submit button).

Code:
<?php echo form_open('process'); ?>
<input type="text" name="q" />
<input type="submit" name="btnSearch" value="Search" />
<?php echo form_close(); ?>

<?php echo form_open('process'); ?>
<input type="text" name="username" />
<input type="password" name="password" />
<input type="submit" name="btnLogin" value="Login" />
<?php echo form_close(); ?>

Code:
function process() {
  $this->load->validation();
  // This is one approach - personally, I would use the if...then to determine the form
  // that was submitted and then call a private method to handle that POST request
  if ($this->input->post('btnSearch')) {
    $rules = array('q' => 'trim');
    $fields = array('q' => 'Search terms');
  } elseif ($this->input->post('btnLogin')) {
    $rules = array('username' => 'required|trim|callback__check_login',
                   'password' => 'required');
    $fields = array('username' => 'username',
                    'password' => 'password');
  }
  $this->validation->set_rules($rules);
  $this->validation->set_fields($fields);

  if ($this->validation->run()) {
    // Do some stuff, based on the type of form that was submitted
  }
}


Messages In This Thread
Two form on Same Page - by El Forum - 07-31-2008, 03:43 AM
Two form on Same Page - by El Forum - 07-31-2008, 03:50 AM
Two form on Same Page - by El Forum - 07-31-2008, 03:57 AM
Two form on Same Page - by El Forum - 07-31-2008, 04:30 AM
Two form on Same Page - by El Forum - 07-31-2008, 04:37 AM
Two form on Same Page - by El Forum - 07-31-2008, 04:38 AM
Two form on Same Page - by El Forum - 07-31-2008, 04:40 AM
Two form on Same Page - by El Forum - 07-31-2008, 04:45 AM
Two form on Same Page - by El Forum - 07-31-2008, 04:45 AM
Two form on Same Page - by El Forum - 07-31-2008, 05:01 AM



Theme © iAndrew 2016 - Forum software by © MyBB