I have two forms in my page. when I submit either of the form, both of them show the same validation error message. I used
if (isset ($_POST['click_cus_button']))
to check what button is licked in the from seems it does not work for me.
Can anyone tell me why this bit of code isn't working?
this is my controller (admin.php)
function add_users_data()
{
if (isset ($_POST['click_cus_button']))// click_cus_button is set load this validation errors
{
$this->form_validation->set_rules('cus_name', 'Name', 'trim|required|min_length[5]');
// validate name
$this->form_validation->set_rules('cus_email', 'Email', 'trim|required|valid_email');
// validate email
$this->form_validation->set_rules('cus_phone', 'Phone Number', 'trim|required|min_length[10]|max_length[10]');
// validate phone number
$this->form_validation->set_rules('cus_password', 'Password', 'required|matches[cus_passconf]');
// validate password
$this->form_validation->set_rules('cus_passconf', 'Retype Password', 'required');
// validate password
if ($this->form_validation->run() == FALSE)// if from validation failed load following pages from views
{
$this->load->view('admin/admin_add_users.php');
}
else // if from validation success load following pages from views
{
$data = array(
'cus_name' => $this->input->post('cus_name'),
'cus_email' => $this->input->post('cus_email'),
'cus_mobile' => $this->input->post('cus_mobile'),
'cus_phone' => $this->input->post('cus_phone'),
'cus_status' => $this->input->post('cus_status')
//'database_field' => $this->input->post('text_box_name')
);
$this->mod_users->add_record($data);//add a comment
$data['result']="Customer Added Successfully ";
$this->load->view('admin/admin_add_users.php',$data);
}
}
else if (isset ($_POST['click_oper_button']))// click_oper_button is set load this validation errors
{
$this->form_validation->set_rules('oper_firstname', 'Name', 'trim|required|min_length[5]');
// validate name
$this->form_validation->set_rules('oper_lastname', 'Name', 'trim|required|min_length[5]');
// validate name
if ($this->form_validation->run() == FALSE)// if from validation failed load following pages from views
{
$this->load->view('admin/admin_add_users.php');
}
else // if from validation success load following pages from views
{
$data['result']="Customer Added Successfully ";
$this->load->view('admin/admin_add_users.php',$data);
}
}
}
this is my View (admin_add_users.php)
I removed some fields to make the code shorter in the view
<?php echo form_open('admin/add_users_data') ?><!-- start of the form -->
<div class="span8">
<div style="padding-bottom:11px;">
<div class="div add_cus box"><!-- start of the add customer add form -->
<?php echo validation_errors('<div class="notice marker-on-bottom bg-darkRed fg-white" id="bottom_form_error">', '</div>'); ?>
<?php
if(isset($result))
{
echo '<div class="notice marker-on-bottom bg-green fg-white">'.$result.'</div>';
}
?>
<!-- Display Validation error massages -->
<feildset>
<legend><i class="icon-user-2 on-right on-left"></i><strong>Add Customer</strong></legend>
<input name='cus_status' type='hidden' value='disabled'/>
<input type="submit" value="Add Customer" class="info" name="click_cus_button">
</feildset>
</div><!-- END of the add customer add form -->
</div>
<div class="div add_oper box"><!-- start of the add Operator add form -->
<?php echo validation_errors('<div class="notice marker-on-bottom bg-darkRed fg-white" id="bottom_form_error">', '</div>'); ?>
<?php
if(isset($result))
{
echo '<div class="notice marker-on-bottom bg-green fg-white">'.$result.'</div>';
}
?>
<feildset>
<legend><i class="icon-user on-right on-left"></i><strong>Add Operator</strong></legend>
<h6>*All fields marked are required</h6>
<lable>Name*</lable><br>
<div class="input-control text size6" data-role="input-control">
<input type="text" name="oper_firstname" placeholder="First Name">
</div>
<div class="input-control text size6" data-role="input-control">
<input type="text" name="oper_lastname" placeholder="Last Name">
</div>
<br>
<div class="input-control radio default-style" data-role="input-control">
<label>
Gender*<br>
<input type="radio" checked="" name="oper_gender">
<span class="check"></span>
Male
</label>
</div>
<div class="input-control radio default-style" data-role="input-control">
<label>
<input type="radio" name="oper_gender">
<span class="check"></span>
Female
</label>
</div>
<br>
<lable>Date of Birth*</lable>
<div class="input-control text" data-role="input-control">
<input id="datepicker" name="oper_dob" type="text">
</div>
<lable>Address*</lable><br>
<div class="input-control text size1" data-role="input-control">
<input type="text" name="oper_add_no" placeholder="No">
</div>
<input type="submit" value="Add Operator" class="info" name="click_oper_button">
</feildset>
</div><!-- END of the add Operator add form -->
<div class="div add_admin">
RadioButton 3 Selected
</div>
</div>
<?php echo form_close(); ?><!-- END of the form -->