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'];
}
Related
i have a problem where the value isn't calculated.
I have function where the user able to update Weight/size and quantity(if the input isn't in readonly). When the user enter a new weight/size it will be auto-calculated in the Order Total. Apparently, there is a value already in the Order Total (since it is an update) so i want it to auto update the value in the order total when the user update the new input in weight/size or quantity.
pls click this picture
here is my updates.blade.php
<div class="col-sm-12 col-md-6" >
<div class="card">
<div class="card-body">
<div class="form-actions">
<div class="container" style="padding: 0;margin: 0;">
<div class="row">
<div class="col-sm-6" >
<span class="float-sm-left">
<h3 class="card-title">Update Order</h3>
</span>
</div>
</div>
</div>
</div>
</br>
<form action="" method="POST" >
#csrf
#method('PUT')
<div class="form-row">
<div class="col-md-4 mb-3">
<label for="validationTooltip01">Order ID</label>
<input type="text" class="form-control" wire:model="orderID" value="" readonly>
</div>
<div class="col-md-4 mb-3">
<label for="validationTooltip02">Order Date</label>
<input type="text" class="form-control" wire:model="orderDate" value="" readonly>
</div>
<div class="col-md-4 mb-3">
<label for="validationTooltipUsername">Order Status</label>
<input type="text" class="form-control" wire:model="orderStatus" value="" readonly>
</div>
</div>
<div class="form-row">
<div class="col-md-6 mb-3">
<label class="form-control-label" >Customer Phone Number</label>
<input type="text" name="" value="" class="form-control" maxlength="11" wire:model="custPhone" readonly>
</div>
<div class="col-md-6 mb-3">
<label class="form-control-label" >Customer Name</label>
<input type="text" name="" value="" class="form-control" maxlength="11" wire:model="custName" readonly>
</div>
</div>
<div class="form-row">
#foreach($serviceOrder as $o)
<div class="col-md-5 mb-3">
<label class="form-control-label" >Service {{ $loop->iteration }} </label>
<input type="text" wire:model="serviceOrder.{{ $loop->index }}.serv.serviceName" class="form-control " readonly>
</div>
<input type="hidden" wire:model="serviceOrder.{{ $loop->index }}.serv.servicePrice" class="form-control col-sm-1 mb-3" readonly>
<div class="col-md-3 mb-3">
<label class="form-control-label" >Weight/Size</label>
<input type="text" name="" value="" wire:model="serviceOrder.{{ $loop->index }}.weightsize" class="form-control">
</div>
<div class="col-md-3 mb-3">
<label class="form-control-label" >Quantity*opt</label>
<input type="text" name="" value="" wire:model="serviceOrder.{{ $loop->index }}.quantity" class="form-control" #if(!$serviceOrder[$loop->index]['quantity']) readonly #endif >
</div>
#endforeach
</div>
<label class="form-control-label" >Order Total RM</label>
<input type="number" wire:model="orderTotal" value="" class="form-control" readonly>
</br>
<div class="form-actions">
<div class="container" style="padding: 0;margin: 0;">
<div class="row">
<div class="col-sm-6" >
<span class="float-sm-left">
<a class="btn btn-primary" href="{{ route('orders.indexInProcess') }}"> Back</a>
</span>
</div>
<div class="col-sm-6">
<span class="float-sm-right">
<div class="text-right">
<button type="submit" class="btn btn-info mr-2">Update</button>
<button type="reset" class="btn btn-dark float-right">Reset</button>
</div>
</span>
</div>
</div>
</div>
</div>
</form>
</div>
</div>
here is the livewire updates.php
<?php
namespace App\Http\Livewire;
use Livewire\Component;
use App\Customer;
use App\Service;
use App\Order;
use App\ServiceOrder;
class Updates extends Component
{
public $orders;
public $orderID;
public $orderDate;
public $orderStatus;
public $orderTotal;
public $custName;
public $custPhone;
public $serviceName;
public $servicePrice;
public $weightsize;
public $quantity;
public $serviceOrder;
public function mount($order,$so)
{
//$orders = Order::with('customer')->get();
//ServiceOrder::with('serv')->where('order_id', $order->id)->get();
$this->orderID = $order->id;
$this->orderDate = $order->orderDate;
$this->orderStatus = $order->orderStatus;
$this->orderTotal = $order->orderTotal;
$this->custPhone = $order->customer->custPhone;
$this->custName = $order->customer->custName;
$this->serviceOrder = $so->toArray();
//dd($this->serviceOrder);
//$so->serviceName,
//$so->weightsize,
//$so->quantity
}
public function render()
{
//$so = ServiceOrder::with('serv')->where('order_id', $order->id)->get();
return view('livewire.updates');
}
public function updatedInputs($name)
{
$array = explode('.', $name);
if ($array[1] == 'serviceName') {
$this->inputs[$array[0]]['servicePrice'] = $this->services->find($value)->servicePrice;
}
try {
$this->calculateTotal();
} catch (\Exception $e) {
}
}
// perform calculation here.
public function calculateTotal(){
$this->orderTotal = $this->orderTotal;
foreach ($this->serviceOrder as $item) {
if($item['quantity'] == ''){
$item['optQuantity']= 1;
$this->orderTotal += ($item['servicePrice'] * $item['weightsize']) * ($item['quantity']);
}else{
$this->orderTotal += $item['servicePrice'] * ($item['weightsize']) * ($item['quantity']);
}
//$this->total *= $item['optQuantity']; // * price;
}
}
}
please help me out here T.T
You can fire event from component (for example) and then register listener in class and call a method for updating total. Check documentation for that.
"Apparently, there is a value already in the Order Total (since it is an update) so i want it to auto update the value in the order total when the user update the new input in weight/size or quantity."
So, the problem is $orderTotal only update once? it doesn't update when user update new input?. Livewire should render everytime there is action or any input.
First of all, i advice u to check what happen when to your function when user update the new input with dd function.
public function calculateTotal(){
dd('is this func work?');
$this->orderTotal = $this->orderTotal;
foreach ($this->serviceOrder as $item) {
if($item['quantity'] == ''){
$item['optQuantity']= 1;
$this->orderTotal += ($item['servicePrice'] * $item['weightsize']) * ($item['quantity']);
}else{
$this->orderTotal += $item['servicePrice'] * ($item['weightsize']) * ($item['quantity']);
}
//$this->total *= $item['optQuantity']; // * price;
}
}
After you debug your function, maybe you already found the answer you looking for or you can come back and ask me anything. ^^
I'm grossly underqualified to be trying what I'm trying but I seem to have things going my way until now. I have an issue with my function which seems like it isn't being called when the form submit button is clicked. Apologies if this is formatted poorly. Please see my code below, Thanks
Functions.php
// UP DATE INFO
function settingsUpdate()
{
// call these variables with the global keyword to make them available in function
global $db;
// receive all input values from the form. Call the e() function
// defined below to escape form values
$usernameU = e($_POST['name']);
$numberU = e($_POST['number']);
$id = (isset($_SESSION['user']['id']));
$error = '0';
if($error == 0){
$query = "UPDATE users SET 'username' 'number' WHERE id==$id
VALUES('$usernameU', '$numberU')";
mysqli_query($db, $query);
echo '<div class="alert alert-primary" role="alert">User Settings Updated Successfully.</div>';
} else {
?><div class="alert alert-danger" role="alert">
<p class="text-center"><strong>Oh snap!</strong> Something went wrong, contact us if you think that's wrong.</p>
</div>,<?php
}
}
Settings.php
<!--begin::Form-->
<form id="settings" class="form" method="post">
<!--begin::Card body-->
<div class="card-body border-top p-9">
<!--begin::Input group-->
<div class="row mb-6">
<!--begin::Label-->
<label class="col-lg-4 col-form-label required fw-bold fs-6">Full Name</label>
<!--end::Label-->
<!--begin::Col-->
<div class="col-lg-8">
<!--begin::Row-->
<div class="row">
<!--begin::Col-->
<div class="col-lg-6 fv-row">
<input type="text" name="username" class="form-control form-control-lg form-control-solid mb-3 mb-lg-0" placeholder="Full Name" value="<?php echo $username; ?>" />
</div>
<!--end::Col-->
</div>
<!--end::Row-->
</div>
<!--end::Col-->
</div>
<!--end::Input group-->
<!--begin::Input group-->
<div class="row mb-6">
<!--begin::Label-->
<label class="col-lg-4 col-form-label fw-bold fs-6">
<span class="required">Contact Number</span>
<i class="fas fa-exclamation-circle ms-1 fs-7" data-bs-toggle="tooltip" title="Phone number must be active"></i>
</label>
<!--end::Label-->
<!--begin::Col-->
<div class="col-lg-8 fv-row">
<input type="number" name="number" class="form-control form-control-lg form-control-solid" placeholder="Phone number" value="<?php echo $_SESSION['user']['number']?>" />
</div>
<!--end::Col-->
</div>
<!--end::Input group-->
</div>
<!--end::Card body-->
<!--begin::Actions-->
<div class="card-footer d-flex justify-content-end py-6 px-9">
<button type="submit" class="btn btn-primary" id="settingsUpdate">Save Changes</button>
</div>
<!--end::Actions-->
</form>
<!--end::Form-->
add action attribute in your form element
<form id="settings" class="form" method="post" action="Functions.php">
......
</form>
In your Functions.php create a class and put your function into
$settingUp = new SettingUp($_POST['username'], $_POST['number']);
$settingUp->settingsUpdate();
class SettingUp
{
protected $username;
protected $number;
function __construct($username, $number)
{
$this->username = $username;
$this->number = $number;
}
function settingsUpdate()
{
$usernameU = $this->username;
$numberU = $this->number;
$id = (isset($_SESSION['user']['id']));
//complete the rest of your code
}
}
You can also include your Functions.php in your settings.php and give the name in your submit button
<?php
include('Functions.php');
?>
<form id="settings" class="form" method="post" action="">
......
<button type="submit" class="btn btn-primary" id="settingsUpdate" name="settingsUpdate">Save Changes</button>
</form>
in your Function.php remove the function and modify the code like this
if(isset($_POST['settingsUpdate'])
{
$username = $_POST['username'];
$number = $_POST['number'];
//add the rest of your code
}
Been trying out codeigniter and wanted to create a form with file upload using the upload class. However when i try to save the form, it didn't respond and just show the same page. I've been looking around, but I can't seem to find out how to make this work.
This is the controller Product.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
Class Product extends CI_Controller{
function __construct(){
parent::__construct();
check_not_login();
$this->load->model('product_m');
}
public function index(){
$data['row'] = $this->product_m->get();
$this->template->load('template', 'product/data/product_data', $data);
}
public function add(){
$product = new stdClass();
$product->product_id = null;
$product->product_name = null;
$product->customer_name = null;
$product->supplier_name = null;
$product->weight = null;
$product->product_date = null;
$product->expired_date = null;
$product->image = null;
$product->barcode = null;
$data = array(
'page' => 'add',
'row' => $product
);
$this->template->load('template', 'product/data/product_form', $data);
}
public function edit($id){
$query = $this->product_m->get($id);
if($query->num_rows()>0){
$product = $query->row();
$data = array(
'page' => 'edit',
'row' => $product
);
$this->template->load('template', 'product/data/product_form', $data);
}else{
echo "<script>alert('Data not found');";
echo "window.location='".site_url('product')."';</script>";
}
}
public function process(){
$post = $this->input->post(null, TRUE);
if(isset($_POST['add'])){
$config['upload_path'] = './uploads/product';
$config['allowed_types'] = 'jpeg|pdf|jpg|png|doc|docs|xls|xlsx';
$config['max_size'] = 5120;
$config['file_name'] = 'product-'.date('ymd').'-'.substr(md5(rand()),0,10);
$this->load->library('upload', $config);
if(#$_FILES['image']['name'] !=null){
if($this->upload->do_upload('image')){
$post['image'] = $this->upload->data('file_name');
$this->product_m->add($post);
if($this->db->affected_rows() > 0){
$this->session->set_flashdata('success', 'Data saved successfully');
}
redirect('product');
}else{
$error = $this->upload->display_errors();
$this->session->set_flashdata('error', $error);
redirect('product/add');
}
}
else{
$post['image'] = null;
$this->product_m->add($post);
if($this->db->affected_rows() > 0){
$this->session->set_flashdata('success', 'Data saved successfully');
}
redirect('product');
}
}else if(isset($_POST['edit'])){
$this->product_m->edit($post);
}
}
public function del($id){
$this->product_m->del($id);
if($this->db->affected_rows() > 0){
$this->session->set_flashdata('Success', 'Data successfully deleted');
}
redirect('product');
}
}
Script for the form product_form.php
<section class="content-header">
<h1>
Product
<small>Add product</small>
</h1>
</section>
<section class ="content">
<div class="box">
<div class="box-header">
<h3 class="box-title"> product</h3>
<div class="pull-right">
<a href="<?=site_url('product')?>" class="btn btn-warning btn-flat">
<i class="fa fa-undo"></i> Back
</a>
</div>
</div>
<div class="box-body">
<div class="row">
<div class="col-md-4 col-md-offset-4">
<?php echo form_open_multipart('product/process');?>
<div class="form-group">
<label>Product Name *</label>
<input type="hidden" name="id" value="<?=$row->product_id?>">
<input type="text" name="product_name" value="<?=$row->product_name?>" class="form-control" required>
</div>
<div class="form-group">
<label>Customer Name *</label>
<input type="text" name="customer_name" value="<?=$row->customer_name?>" class="form-control" required>
</div>
<div class="form-group">
<label>Supplier Name *</label>
<input type="text" name="supplier_name" value="<?=$row->supplier_name?>" class="form-control" required>
</div>
<div class="form-group">
<label>Weight(kg) *</label>
<input type="number" name="weight" value="<?=$row->weight?>" class="form-control" required>
</div>
<div class="form-group">
<label>Product Date(dd/mm/yyyy) *</label>
<input type="text" name="product_date" value="<?=$row->product_date?>" class="form-control" required>
</div>
<div class="form-group">
<label>Expired Date(dd/mm/yyyy) *</label>
<input type="text" name="expired_date" value="<?=$row->expired_date?>" class="form-control" required>
</div>
<div class="form-group">
<label>Technical Data</label>
<input type="file" name="image" class="form-control" >
</div>
<!-- FORM BARCODE -->
<div class="form-group">
<label>Barcode</label>
<input name="barcode" class="form-control" value="
<?php
$angka = rand(1000000,9999999);
$random = rand(0,25);
$random1 = rand(0,25);
$random2 = rand(0,25);
$name = array("A", "B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q",
"R","S","T","U","V","W","X","Y","Z");
echo $name[$random],$name[$random1],$name[$random2],$angka;
$row->barcode
?>" readonly>
</div>
<div class="form-group">
<button type="submit" name="<?=$page?>" class="btn btn-success btn-flat">
<i class="fa fa-paper-plane"> Save</i>
</button>
<button type="Reset" class="btn btn-flat"> Reset</button>
</div>
<!-- </form> -->
<?php echo form_close();?>
</div>
</div>
</div>
</div>
</section>
Load the form helper.
function __construct(){
parent::__construct();
check_not_login();
$this->load->model('product_m');
$this->load->helper('form');
}
I am trying to send multiple files in one request using DropZone js.
<script type="text/javascript">
Dropzone.autoDiscover = false;
var file= new Dropzone(".dropzone",{
url: any url,
method:"post",
paramName:"PhotoFiles",
addRemoveLinks:true,
autoProcessQueue: false
});
//Upload file onsubmit
$('#UploadMultiFiles').submit(function(){
file.processQueue();
});
file.on("sending",function(a,b,c){
a.token=Math.random();
c.append("token",a.token);
});
The issue is I have other inputs in the same form that is why I used onsubmit, and these inputs are saved in a table and the images from dropzone are saved in another table with and both tables have one to many relationship
The Controller like:
public function university_offers($id){
$data['university_offer_name']=$this->input->post('university_offer_name');
$data['university_id_fk']=$this->input->post('university_id_fk');
$data['university_offer_details']=$this->input->post('university_offer_details');
if ($this->input->post('save')){
$data2['university_offer_id_fk'] = insertrecords('university_offers',$data);
$data2['university_id_fk'] = $data['university_id_fk'];
//when I put the next IF at the begining of the function it works but ofcourse without the other data fields that I need.
if(isset($_FILES) && $_FILES != null){
$data2['photo_name'] = upload_image('PhotoFiles');
insertrecords('university_offer_photos',$data2);
}
if (insertrecords('university_offer_photos',$data2)==true)
message('success','');
redirect('Admin/university_offers/0','refresh');
}
$data['view']="admin/universities/university_offers";
$this->load->view('index',$data);
}
What I need is sending al uploaded files and do a loop in the controller to save it right in the database, not sending each file to the controller and saving it.
Edit:
My view is like:
<form action="university_offers/<?=$id?>" id="UploadMultiFiles" autocomplete="off" method="post" enctype="multipart/form-data" class="m-t-5" novalidate>
<div class="form-body">
<h3 class="card-title">بيانات العرض</h3>
<hr>
<div class="row p-t-20">
<div class="col-md-6">
<div class="form-group">
<label class="control-label">إسم العرض<span class="text-danger">*</span></label>
<div class="controls">
<input type="text" autocomplete="off" name="university_offer_name" class="form-control" required value="<?php if(isset($result)) echo $result['university_offer_name']?>" data-validation-required-message="يجب إدخال إسم العرض" placeholder="إسم العرض">
</div>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label class="control-label">إسم الجامعة<span class="text-danger">*</span></label>
<div class="controls">
<select name="university_id_fk" id="select" class="form-control" required data-validation-required-message="يجب إختيار الجامعة" aria-invalid="false">
<option value="">إختر الجامعة</option>
<?php
foreach (selectrecords("*",'universities') as $university):
$select = '';
if(isset($result) && $result['university_id_fk'] == $university->university_id_pk)
$select = 'selected';
?>
<option <?=$select?> value="<?php echo $university->university_id_pk ?>"><?php echo $university->university_name ?></option>
<?php endforeach;?>
</select>
</div>
</div>
</div>
<div class="col-md-12">
<div class="form-group">
<label class="control-label">تفاصيل العرض<span class="text-danger">*</span></label>
<div class="controls">
<textarea id="mymce" name="university_offer_details"><?php if(isset($result)) echo $result['university_offer_details'] ?></textarea>
</div>
</div>
</div>
<div class="col-md-12">
<div class="form-group">
<label class="control-label">صور العرض<span class="text-danger">*</span></label>
<div class="row">
<?php
if(isset($result)) {
foreach (selectrecords('*','university_offer_photos',array('university_offer_id_fk'=>$result['university_offer_id_pk'])) as $photo):
echo'
<div class="form-group text-center" id="'.$photo->photo_id_pk.'">
<div class="col-md-12">
<img style="border: none; height: 150px; width: 150px; border-radius: 10px;" class="img-thumbnail" src="'.base_url().'public/uploads/images/'.$photo->photo_name.'">
</div>
حذف الملف
</div>
';
endforeach;
}
?>
</div>
<div class="dropzone">
<div class="dz-message">
<span> Drag and Drop your files here Or Click here to upload</span>
</div>
</div>
</div>
</div>
</div>
<div class="form-actions">
<input type="hidden" id="url" value="university_offers/<?=$id?>" />
<?php
if($id == 0)
echo '<button type="submit" id="butt" name="save" value="save" class="btn btn-primary"> <i class="fa fa-check"></i> حفظ</button>';
else
echo '<button type="submit" id="butt" name="edit" value="edit" class="btn btn-primary"><i class="fa fa-check"></i> حفظ</button>';
?>
<button type="reset" class="btn btn-inverse"><i class="fa fa-times"></i> إلغاء</button>
<?php
if($id == 0)
echo'<button type="button" id="backword" class="btn btn-second"><i class="fa fa-undo"></i> رجوع</button>';
else{
echo '<input type="hidden" name="university_offer_id_pk" value="'.$result['university_offer_id_pk'].'"/>
<button type="button" class="btn btn-second"><i class="fa fa-undo"></i> رجوع</button>';
}
?>
</div>
</div>
</form>
upload_image function, I put it in the Helper
function upload_image($file_name){
$CI =& get_instance();
$config['upload_path'] = 'public/uploads/images';
$config['allowed_types'] = 'gif|Gif|ico|ICO|jpg|JPG|jpeg|JPEG|BNG|png|PNG|bmp|BMP|WMV|wmv|MP3|mp3|FLV|flv|SWF|swf';
$config['max_size'] = '1024*8';
$config['encrypt_name']=true;
$CI->load->library('upload',$config);
if(! $CI->upload->do_upload($file_name)){
return false;
}else{
$datafile = $CI->upload->data();
thumb($datafile);
watermark($datafile);
return $datafile['file_name'];
}}
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
}