I have created an Add User form in codeignitor which has the link http://example.com/users/add. And in the controller I have the following code for form validation:
$this->form_validation->set_rules('firstName', 'First Name', 'required');
$this->form_validation->set_rules('lastName', 'Last Name', '');
$this->form_validation->set_rules('guardian1', 'Guardian First', 'required');
$this->form_validation->set_rules('guardian2', 'Guardian Second', '');
$this->form_validation->set_rules('mobile', 'Mobile Number', 'required');
$this->form_validation->set_rules('phone', 'Phone Number', '');
$this->form_validation->set_rules('dob', 'Date Of Birth', 'required');
$this->form_validation->set_rules('status', 'Account Status', 'required');
$this->form_validation->set_rules('confirmation', 'Confirm Creation', 'required');
if ($this->form_validation->run == FALSE)
{
redirect('news');
}
else
{
redirect('users/view');
}
When I try to access the url to add user, it directly redirects me to http://example.com/news without opening the form page where I can fill the form. This is my form code for Add User form:
<form id="form-project" role="form" method="post" action="<?php echo base_url(); ?>users/add" autocomplete="off" novalidate>
<div class="form-group-attached">
<div class="row clearfix">
<div class="col-md-6">
<div class="form-group form-group-default required">
<label>First name</label>
<input type="text" class="form-control" name="firstName" required>
</div>
</div>
<div class="col-md-6">
<div class="form-group form-group-default">
<label>Last name</label>
<input type="text" class="form-control" name="lastName">
</div>
</div>
</div>
<div class="row clearfix">
<div class="col-md-6">
<div class="form-group form-group-default required">
<label>Parent I / Guardian</label>
<input type="text" class="form-control" name="guardian1" required>
</div>
</div>
<div class="col-md-6">
<div class="form-group form-group-default">
<label>Parent II / Guardian</label>
<input type="text" class="form-control" name="guardian2">
</div>
</div>
</div>
<div class="row clearfix">
<div class="col-md-6">
<div class="form-group form-group-default required">
<label>Mobile</label>
<input type="text" class="form-control" name="mobile" required>
</div>
</div>
<div class="col-md-6">
<div class="form-group form-group-default">
<label>Phone</label>
<input type="text" class="form-control" name="phone">
</div>
</div>
</div>
<div class="row clearfix">
<div class="col-md-6">
<div class="form-group form-group-default input-group required">
<div class="form-input-group">
<label>Date Of Birth</label>
<input id="start-date" type="text" class="form-control date" name="dob" required>
</div>
</div>
</div>
<div class="col-md-6">
<div class="form-group form-group-default input-group">
<div class="form-input-group">
<label class="inline">Account Status</label>
</div>
<div class="input-group-addon bg-transparent h-c-50">
<input type="checkbox" name="status" data-init-plugin="switchery" data-size="small" data-color="primary" checked="checked" required />
</div>
</div>
</div>
</div>
</div>
<br>
<div class="pull-left">
<div class="checkbox check-primary">
<input type="checkbox" checked="unchecked" value="1" id="checkbox-agree" name="confirmation">
<label for="checkbox-agree">I hereby certify that the information above is true and accurate
</label>
</div>
</div>
<br>
<button class="btn btn-primary" type="submit">Submit</button>
<button class="btn btn-default" type="reset"><i class="pg-close"></i>Clear</button>
</form>
P.s I have the form validation library and url helper loaded.