Sorry, i want the create Form input using drop down from database. but i've try to created and error like this.
My Code in controller
public function ajax_add()
{
$data = array(
'date_man_activity_ra' => $this->input->post('date_man_activity_ra',TRUE),
'dd_user' => $this->mymodel->dd_user(),
'user_selected' => $this->input->post('id_user') ? $this->input->post('id_user') : '',
'id_user' => $this->input->post('id_user',TRUE),
'note' => $this->input->post('note',TRUE),
);
$insert = $this->Man_activity->save($data);
echo json_encode(array("status" => TRUE));
}
and mymodel
public function dd_user()
{
// ambil data dari db
$this->db->order_by('id_user', 'asc');
$result = $this->db->get('ops_user');
// bikin array
// please select berikut ini merupakan tambahan saja agar saat pertama
// diload akan ditampilkan text please select.
$dd[''] = 'Please Select';
if ($result->num_rows() > 0) {
foreach ($result->result() as $row) {
// tentukan value (sebelah kiri) dan labelnya (sebelah kanan)
$dd[$row->id_user] = $row->username;
}
}
return $dd;
}
and my View
<div class="modal fade" id="modal_form" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h3 class="modal-title">Person Form</h3>
</div>
<div class="modal-body form">
<form action="#" id="form" class="form-horizontal">
<input type="hidden" value="" name="id"/>
<div class="form-body">
<div class="form-group">
<label class="control-label col-md-3">date_man_activity_ra</label>
<div class="col-md-9">
<input name="date_man_activity_ra" placeholder="yyyy-mm-dd" class="form-control datepicker" type="text">
<span class="help-block"></span>
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3">Id User</label>
<div class="col-md-9">
<?php
$dd_user_attribute = 'class="form-control select2"';
echo form_dropdown('id_user', $dd_user, $user_selected, $dd_user_attribute);
?>
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3">Note</label>
<div class="col-md-9">
<input name="note" placeholder="note" class="form-control" type="text">
<span class="help-block"></span>
</div>
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" id="btnSave" onclick="save()" class="btn btn-primary">Save</button>
<button type="button" class="btn btn-danger" data-dismiss="modal">Cancel</button>
</div>
</div>
</div>
how to solve it? or Another ways?
Thank You
public function ajax_add()
{
$data = array(
'date_man_activity_ra' => $this->input->post('date_man_activity_ra',TRUE),
'dd_user' => $this->mymodel->dd_user(),
'user_selected' => $this->input->post('id_user') ? $this->input->post('id_user') : '',
'id_user' => $this->input->post('id_user',TRUE),
'note' => $this->input->post('note',TRUE),
);
$insert = $this->Man_activity->save($data);
// Load your view and pass the data that you use in dropdown
//echo json_encode(array("status" => TRUE)); // Remove it
}
Related
Using codeigniter 4 (PHP) and javascript for the modal. I am trying to pass the value of "rjuid" (html input type hidden) to the controller variable $uid, but I always get NULL value for $uid.
This is my code in view under a modal.
<div class="modal fade" id="RejoinModal" tabindex="-1" role="dialog" aria-labelledby="reJoinModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<?php
$attributes = ['class' => 'frmReJoinUser', 'id' => 'frmRJTUid'];
echo form_open('rejoin_term_user', $attributes);
?>
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="reJoinModalLabel">Rejoin User</h4>
</div>
<div class="modal-body">
<?php
$data = [
'type' => 'hidden',
'name' => 'rjuid',
'id' => 'rjuid',
'value' => '',
'class' => 'form-control',
];
echo form_input($data);
?>
<div class="form-group">
<label for="rejoin_date">Rejoin Date:</label>
<input type="date" class="form-control" id="rejoin_date" placeholder="Enter Rejoin Date" name="rejoin_date" required>
</div>
<div class="form-group">
<label for="name">Remarks (if any):</label>
<textarea rows="2" cols="50" class="form-control" id="remarks" placeholder="Enter Remarks" name="remarks"></textarea>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-bs-dismiss="modal">Close</button>
<button type="submit" id='btnReJoinTermUser' class="btn btn-primary">Rejoin user</button>
</div>
<?php echo form_close(); ?>
</div>
</div>
</div>
This is my controller (rejoin_term_user.php)
public function rejoin_term_user(){
$request = \Config\Services::request();
echo "<h1> Rejoin Term </h1>";
$uid = $request->getPost('rjuid');
// $uid = $this->request->getPost('rjuid');
// $uid = $this->request->getVar('rjuid');
// $uid = $this->request->getPostGet('rjuid');
dd($uid);
}
Note: I already tried those codes that are commented in the controller, but still I get Null value for $uid.
I have a page with a form that has dynamic inputs, where the user can add and "remove" lines. (By "removes," I mean that it removes from the front end but doesn't actually remove from the database.) The functionality works, as far as updating existing rows and adding new rows. The problem I'm having is with deleting rows.
I'd like to have a modal popup that confirms that they want to delete the row before it deletes it. My first thought was to loop through the existing rows and create a corresponding modal per row with a form, but I'm stuck on setting up the controller to recognize which form/row it's looking to delete - so to recap there's going to be one form with dynamic fields (this is the one that works right now), and there's going to be multiple dynamic forms for deleting rows.
Here's my HTML:
<form action="{{route('preliminary-children.updateChildren')}}" method="POST">
#csrf
<!-- Content Row -->
<div class="row" id="childInfo">
<!-- About Process -->
<div class="col-xl-12 col-lg-12">
<div class="card shadow mb-4">
<!-- Card Header - Dropdown -->
<div class="card-header py-3 d-flex flex-row align-items-center justify-content-between">
<h6 class="m-0 font-weight-bold text-secondary">Family Information - Children</h6>
</div>
<div id="dynamic_field">
#foreach($children as $i => $child)
<div class="card-body" id="row{{$i+1}}">
#if ($i != 0)
<hr/>
<div class="text-right px-2 my-2 child-{{$i+1}}">
<a href="#" class="text-decoration-none" data-toggle="modal" data-target="#remove{{$i+1}}">
<button type="button" class="px-0 btn btn-circle btn-danger">
<i class="fal fa-times"></i>
</button>
</a>
</div>
<div class="modal fade" id="remove{{$i+1}}" tabindex="-1" role="dialog" aria-labelledby="label{{$i+1}}" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="label{{$i+1}}">Delete Row</h5>
<button class="close" type="button" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">Are you sure you want to remove this row?</div>
<div class="modal-footer">
<button class="btn bg-gray-300" type="button" data-dismiss="modal">Cancel</button>
<form id="remove-form{{$i+1}}" name="formrow[]" action="{{route('preliminary-children.updateChildren')}}" method="POST" class="d-inline-block">
<input type="text" name="removeID[]" id="removeID{{$i+1}}" value="{{$child->id}}" hidden="hidden">
<button type="submit" id="{{$i+1}}" name="removerow[]" class="btn btn-danger text-decoration-none btn_remove">Remove</button>
</form>
</div>
</div>
</div>
</div>
#endif
<input type="text" name="userID[]" id="userID{{$i+1}}" value="{{ $user->id }}" hidden="hidden">
<input type="text" name="ID[]" id="childID{{$i+1}}" value="{{$child->id}}" hidden="hidden">
<input type="text" name="rel[]" id="rel{{$i+1}}" value="child" hidden="hidden">
<div class="form-row">
<div class="form-group col-md-6">
<label for="first">First Name</label>
<input name="first[]" type="text" class="form-control" id="first{{$i+1}}" value="{{$child->first_name}}" placeholder="First Name">
</div>
<div class="form-group col-md-6">
<label for="last">Last Name</label>
<input name="last[]" type="text" class="form-control" id="last{{$i+1}}" value="{{$child->last_name}}" placeholder="Last Name">
</div>
</div>
<div class="form-row">
<div class="form-group col-md-6">
<label for="inputSSN">SSN</label>
<input data-inputmask="'mask': '999-99-9999'" value="{{$child->ssn}}" type="text" class="form-control" name="inputSSN[]" id="SSN{{$i+1}}" placeholder="SSN">
</div>
<div class="form-group col-md-6">
<label for="dob">Date of Birth</label>
<input data-inputmask="'mask': '99/99/9999'" type="datepicker" value="{{$child->dob}}" class="form-control" name="dob[]" id="do{{$i+1}}B" placeholder="Date of Birth">
</div>
</div>
<div class="form-row">
<div class="form-group col-md">
<label for="inputGender">Gender</label>
<br/>
<select class="form-control d-inline-block w-25 mr-1" name="inputGender[]" id="Gender{{$i+1}}" placeholder="Gender">
#foreach($genders as $gender)
<option value="{{$gender}}" #if($child){{ ($child->gender == $gender) ? 'selected' : ''}} #endif>{{$gender}}</option>
#endforeach
</select>
</div>
<div class="form-group col-md">
<label for="primaryHeight">Height</label>
<br/>
<select class="form-control d-inline-block w-25 mr-1" name="primaryFeet[]" id="primaryFeet{{$i+1}}">
#foreach($feet as $foot)
<option value="{{$foot}}" #if($child){{($child->height_feet == $foot) ? 'selected' : ''}} #endif>{{$foot}}</option>
#endforeach
</select>
<span class="d-inline-block w-10 mr-3">ft</span>
<select class="form-control d-inline-block w-25 mr-1" name="primaryInches[]" id="primaryInches{{$i+1}}">
#foreach($inches as $inch)
<option value="{{$inch}}" #if($child){{($child->height_inch == $inch) ? 'selected' : ''}} #endif>{{$inch}}</option>
#endforeach
</select>
<span class="d-inline-block w-10">in</span>
</div>
<div class="form-group col-md">
<label for="primaryWeight">Weight (lbs)</label>
<br/>
<input type="number" min="0" step=".1" class="form-control d-inline-block w-75 mr-1" id="primaryWeight{{$i+1}}" value="{{$child->weight_lbs}}" name="primaryWeight[]" placeholder="Weight (lbs)">
<span class="d-inline-block w-10">lbs</span>
</div>
</div>
</div>
#endforeach
</div>
<hr/>
<div class="text-center my-4">
<button type="button" name="add" id="add" class="btn btn-success">Add More</button>
</div>
</div>
</div>
</div>
<div class="form-row mb-4 text-center">
<div class="form-group col-md-12 mt-4">
Go Back <button type="submit" name="savecontinue" class="btn btn-info">Save and Continue</button>
</div>
</div>
</form>
And here's my controller:
public function updateChildren(Request $request)
{
$id = Auth::user()->id;
$user = Auth::user();
$family = UserFamily::where(['user_id'=> $id, 'rel' => 'child'])->get();
$count = count($family);
$children = ($count > 0 ? $family : '');
$input = $request->all();
$rules = [
'first[*]' => 'required',
'userID[*]' => 'required',
'rel[*]' => 'required',
'first[*]' => 'required',
'last[*]' => 'required',
'inputSSN[*]' => 'required',
'dob[*]' => 'required',
'inputGender[*]' => 'required',
'primaryFeet[*]' => 'required',
'primaryInches[*]' => 'required',
'primaryWeight[*]' => 'required',
];
$validator = Validator::make($request->all(), $rules);
if ($validator->passes()) {
foreach($input['userID'] as $index => $value) {
$feet = $input['primaryFeet'][$index];
$inch = $input['primaryInches'][$index];
$weight = $input['primaryWeight'][$index];
$inches = ($feet * 12) + $inch;
$bmi = number_format(((703 * $weight) / ($inches * $inches)), 2, '.', '');
if(isset($input['ID'][$index])){
$famid = $input['ID'][$index];
}else {
$famid = '';
}
if($famid > 0 || $famid != '') {
$user = UserFamily::firstOrNew(['user_id'=> $id, 'rel' => 'child', 'id' => $famid]);
}else{
$user = UserFamily::create(['user_id'=> $id, 'rel' => 'child']);
}
$user->user_id = $id;
$user->bmi = $bmi;
$user->first_name = $input['first'][$index];
$user->dob = $input['dob'][$index];
$user->last_name = $input['last'][$index];
$user->rel = $input['rel'][$index];
$user->ssn = $input['inputSSN'][$index];
$user->gender = $input['inputGender'][$index];
$user->height_feet = $input['primaryFeet'][$index];
$user->height_inch = $input['primaryInches'][$index];
$user->weight_lbs = $input['primaryWeight'][$index];
$user->save();
}
return redirect()->route('preliminary-review');
}
return redirect()->route('preliminary-children')->withErrors($validator);
}
The only thing I've tried is setting up an if/else if($request->has('savecontinue'){ ... } and wrapping my existing controller in that. The else{} would handle all the modals, but it kept kicking back errors as if all my syntax was incorrect.
Thoughts? I'm also not opposed to approaching this differently if there's a better way.
PS, there's JS for the remove and add buttons, but I didn't think it was necessary for this question. If you need me to update this with it, I can. :)
Deleting a child is a different operation than updating a child, so you should have a different method for it in your controller. Not sure about how you've got anything named, but this should give you an idea.
Define a new route:
Route::delete('/whatever/{child}', [ChildController::class, 'deleteChild'])
->name('preliminary-children.deleteChild');
Note we'll use the delete HTTP method to access this route, and the ID is passed as part of the URL.
Update your view to point to this new route:
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="label{{$i+1}}">Delete Row</h5>
<button class="close" type="button" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">Are you sure you want to remove this row?</div>
<div class="modal-footer">
<button class="btn bg-gray-300" type="button" data-dismiss="modal">Cancel</button>
<form id="remove-form{{$i+1}}" name="formrow[]" action="{{route('preliminary-children.deleteChild', $child->id)}}" method="POST" class="d-inline-block">
<input name="_method" value="DELETE" type="hidden"/>
<button type="submit" id="{{$i+1}}" name="removerow[]" class="btn btn-danger text-decoration-none btn_remove">Remove</button>
</form>
</div>
</div>
</div>
A web browser can't send a delete request, so we spoof the method with a hidden input.
And then we make the method:
public function deleteChild(UserFamily $child)
{
$child->delete();
return response()->json("success");
}
By type hinting the parameter, Laravel automatically looks up the relevant record in the database for you. Of course you'll want to do some error checking there too.
I want to validate every data that the user input in modal. The problem is not working at all, even I put the "required" in the text input same problem. It accept empty string. I don't want to accept empty string and the maximum length that user can input 45. I used bootstrap to create a modal and PHP for server side
<?php require_once('../../private/initialize.php'); ?>
<?php
if($_SERVER['REQUEST_METHOD'] == "POST") {
$validation = new Validation();
$data = [
"category_description" => $_POST['category_description']
];
$validation->validate($data, [
"category_description" => "required|maxlen:45"
]);
$errors = $validation->getErrors();
} else {
$data = [
"category_description" => ""
];
$errors = [
"category_description" => ""
];
}
if (isset($_POST['submit'])) {
if($data) {
echo $data;
}
<div class="modal" id="myModal1" > <!-- start update modal -->
<div class="modal-dialog">
<div class="modal-content " style="height:auto">
<!-- Modal Header -->
<div class="modal-header">
<h4 class="modal-title">Update Category</h4>
<button #click="clearData" type="button" class="close" data-dismiss="modal"><i class="fas fa-times"></i></button>
</div>
<!-- Modal body -->
<form method="post" action="unit_category/index.php">
<div class="modal-body">
<div class="form-group">
<div class="col-lg-12">
<input type="hidden" class="form-control" id="category_id" name="category_id" v-model="category_id" disabled>
</div>
</div>
<div class="form-group">
<div class="col-lg-12">
<input type="text" id="category_description" name="category_description" v-model="category_description" value="<?php echo $data['category_description'] ?>" placeholder="Enter Description" class="form-control <?php if(!empty($errors['category_description'])) { echo 'is-invalid'; } ?>" required>
<div class="invalid-feedback"><?php echo $errors['category_description'] ?></div>
</div>
</div>
</div>
<!-- Modal footer -->
<div class="modal-footer">
<button type="submit" #click="updateCategory" class="btn btn-primary" data-dismiss="modal">Update Category</button>
</div>
</form>
</div>
</div>
</div> <!-- end update modal -->
I am using Laravel to create a project but I get some issue when creating a form that uses date:
Is there something missing in the table or script?
Here the table
Here the controller
public function index(Request $request){
$data = array();
if($request->isMethod('post') == "post"){
$pendaftar = new PendaftarModel();
$pendaftar->tgl =$request->input(['date']);
$pendaftar->nopol =$request->input('no polisi');
$pendaftar->motor =$request->input('jenis service');
$pendaftar->servis =$request->input('keluhan kendaraan');
$pendaftar->keluhan =$request->input('keluhan kendaraan');
// $pendaftar->keluhan =$request->input('keluhan kendaraan');
if($pendaftar->save()){
$data["status"] = "success";
$data["message"] = "Selamat, booking berhasil. Staff kami akan segera menghubungi anda untuk penjadwalan";
}else {
$data["status"] = "danger";
$data["message"] = "Maaf, Booking Gagal";
}
}
return view("daftar", $data);
The view blade
div class="well well-lg">
<div class="container">
<h2>Booking Online</h2>
<span>Halaman untuk melakukan pendaftaran kendaraan.</span>
</div>
</div>
<div class="container">
<div class="alert alert-info">
<i class="glyphicon glyphicon-info-sign"></i> Silahkan isi data berikut
</div>
<div class="panel panel-primary">
<div class="panel-heading">
Form Data Kendaraan
</div>
<div class="panel-body">
#if(isset($status))
<div class="alert alert-<?php echo $status; ?>">
<?php echo $message; ?>
</div>
#endif
<form method="post">
{{ csrf_field() }}
<div class="form-group">
<label for="tanggal">Pilih Tanggal</label>
<input class="form-control" id="tanggal" required type="date" name="tgl" max="3000-12-31"
min="1000-01-01" placeholder="Pilih Tanggal">
</div>
<div class="form-group">
<label for="nopol">Nomor Polisi:</label>
<input class="form-control" id="nopol" required type="text" name="nopol" placeholder="Masukkan No Polisi">
</div>
<div class="form-group">
<label for="motor">Jenis Motor:</label>
<input class="form-control" id="motor" required type="text" name="motor" placeholder="Matic/Bebek/Sport">
</div>
<div class="form-group">
<label for="servis">Tipe Service:</label>
<input class="form-control" id="servis" required type="text" name="servis" placeholder="Besar/Kecils">
</div>
<div class="form-group">
<label for="keluhan">Keluhan Kendaraan:</label>
<textarea name="keluhan" id="keluhan" required class="form-control" rows="5" placeholder="Tulis Keluhan Motor Anda"></textarea>
</div>
<button type="submit" name="submit" class="btn btn-success btn-lg"><i class="glyphicon glyphicon-send"></i> Submit</button>
<button type="reset" class="btn btn-danger btn-lg">Reset</button>
</form>
</div>
</div>
</div>
The Model
{
//
protected $table = "pendaftar";
public $timestamps = true;
protected $fillable=['tgl','nopol','motor','servis','keluhan'];
}
In the snapshot, Your table is missing updated_at column, create a column with the name "updated_at" in your pendafter table.
Another way you can set the model like this:
{
//
protected $table = "pendaftar";
public $timestamps = false; //it should be false
protected $fillable=['tgl','nopol','motor','servis','keluhan'];
}
I am trying to save data inserted from a modal. Now i have a view called users where i show the list of users.now if admin clicks on add more users it opens a bootstap modal where i have a field called no of users requested. So whatever value the admin fills that must be save into database. I am confused on how to save this.
Edited...................................................
After reseller logs in he can request more users to admin so i created that modal to request the users required so i want to store the number of users required by that reseller along with his/her key
My Controller is :
public function index ()
{
$usertype=$this->session->userdata('usertype');
if($usertype ==="reseller")
{
$key= $this->session->userdata('key');
$this->db->where("key",$this->session->userdata('key'));
$this->data['users'] = $this->user_m->get();
// Load view
$this->data['subview'] = 'reseller/user/index';
$this->load->view('reseller/_layout_main', $this->data);
}
else
{
$this->load->view('permission');
}
}
My view Is :
Request More Users
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Add the number of users you want</h4>
</div>
<div class="modal-body">
<form id="loginForm" method="post" class="form-horizontal">
<div class="form-group">
<label class="col-xs-3 control-label">Number Of Users</label>
<div class="col-xs-5">
<input type="text" class="form-control" name="username" id="spinnerInput" />
</div>
</div>
<div class="form-group">
<label class="col-xs-3 control-label">Password</label>
<div class="col-xs-5">
<input type="password" class="form-control" name="password" />
</div>
</div>
<div class="form-group">
<div class="col-xs-5 col-xs-offset-3">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
Your question unclear but will give it ago. On your form you need to have form action if you do not have it then will not work. make sure also url helper is auto loaded.
Docs http://www.codeigniter.com/docs
Also would look into codeigniter form validation http://www.codeigniter.com/user_guide/libraries/form_validation.html
And form helper
http://www.codeigniter.com/user_guide/helpers/form_helper.html
<form action="<?php echo base_url('controller-name/function');?>" method="post" method="post">
You may need to use index.php in base_url();
<form action="<?php echo base_url('index.php/controller-name/function');?>">
View
Request More Users
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Add the number of users you want</h4>
</div>
<div class="modal-body">
<form id="loginForm" method="post" class="form-horizontal" action="<?php echo base_url('controller-name/request');?>">
<div class="form-group">
<label class="col-xs-3 control-label">Number Of Users</label>
<div class="col-xs-5">
<input type="text" class="form-control" name="username" id="spinnerInput" />
</div>
</div>
<div class="form-group">
<label class="col-xs-3 control-label">Password</label>
<div class="col-xs-5">
<input type="password" class="form-control" name="password" />
</div>
</div>
<div class="form-group">
<div class="col-xs-5 col-xs-offset-3">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
</form>
</div>
Model
class User_m extend CI_Model {
function request_user() {
$data = array(
'key' => $this->session->userdata('key'),
'total_user' => $this->get_total(), // create a column in table
'username' => $this->input->post('username')
);
$this->db->insert('table', $data);
}
function request_update_user() {
$data = array(
'total_user' => $this->get_total() // create a column in table
'username' => $this->input->post('username')
);
$this->db->where('key', $this->session->userdata('key'));
$this->db->update('table', $data);
}
function get() {
$this->db->where('key', $this->session->userdata('key'));
$query = $this->db->get('table');
return $query->result_array();
}
function get_total() {
$this->db->where('key', $this->session->userdata('key'));
$query = $this->db->get('table');
return $query->num_rows();
}
}
Controller
class Reseller extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->model('user_m');
}
public function index () {
$usertype = $this->session->userdata('usertype');
if($usertype == "reseller") {
$this->data['users'] = $this->user_m->get();
// Load view
$this->data['subview'] = 'reseller/user/index';
$this->load->view('reseller/_layout_main', $this->data);
} else {
$this->load->view('permission');
}
}
public function request() {
$this->load->library('form_validation');
$this->form_validation->set_rules('username', 'Username', 'required');
if ($this->form_validation->run() == FALSE) {
$this->load->view('modal_view');
} else {
$this->user_model->request_user();
redirect('your_controller');
}
}
}