Error
Not able to pass the value from this application to other website.
View
In this view using action i have called the controller function. If the user selects Pay-Me then value 1 will be passed to controller function.
<form id="formMuktinath" method="post" action="<?php echo base_url().'index.php/booking/bookManakamana'?>">
<div class="form-group">
<label for="name" class="col-sm-3 col-lg-offset-2 control-label">Payment From </label>
<div class="col-sm-4">
<select class="select form-control" name="manakamana[payment_from]">
<option value="1" selected>Pay-Me</option>
<option value="2">BIL</option>
</select>
</div>
</div>
<div class="form-group">
<div class="col-md-offset-5">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
</form>
Controller
If 1 is selected then it calls payme website. Then there redirect function using $data does not pass amt value to payme website.
public function bookManakamana(){
if ($data = $this->input->post('manakamana')) {
$data['created_on'] = date('Y-m-d H:i:s');
if ($data['payment_from'] == '1') {
$data['amt'] = '100';
redirect('http://dev.payme.com/pay/main',$data);
}
if ($data['payment_from'] == '2') {
echo 'bli';
exit;
}
redirect('booking/index');
} else {
$this->load->view('index');
}
}
if you want to pass values in link as get variable
www.somewebsite.com/?var='value'
but if you want to send variable as post you need to use curl
Related
I want to update customer order status at admin panel. How to pass the radio button value to the controller using form.
Blade file
<form action="{{url('vendor/orderstatus-update/' .$order->id)}}" method="POST" >
{{ csrf_field() }}
<div class="card-body">
<h4 class="card-title">Order Status</h4>
<div class="form-group">
<div class="col-md-6">
<input type="radio" name="order_status" id="Pending" value="Pending" > Pending<br>
<input type="radio" name="order_status" id="Processing" value="Processing" > Processing<br>
<input type="radio" name="order_status" id="Delivery" value="Delivery" > Out For Delivery<br>
<input type="radio" name="order_status" id="Cancelled" value="Cancelled" > Cancelled<br>
</div>
</div>
<button type="submit" class="btn btn-primary">Update</button>
</div>
</form>
Below code is the function I write in controller
public function updateOrderStatus(Request $request,$orderId){
$orders=Order::where('order_id',$orderId)->find();
$orders->update(['order_status'=>$request['order_status']]);
return response()->json(['status'=>true],200);
}
order table
The error that I get is:
{"success":false,"message":"A non well formed numeric value encountered"}
Any solution to fix this?
You can try like this.
public function updateOrderStatus(Request $request,$orderId)
{
try
{
$inputs = $request->all();
$orders = Order::where('order_id', $orderId)->find();
$orders->update(['order_status' => $inputs['order_status']]);
return response()->json(['status' => true], 200);
} catch (\Throwable $th) { dd($th->__toString()); }
}
I'm developing a web application, and I want to pass variable called ID when the form method is post that linked to open other form but in the config/routes I'm using $routes[page_A][get] = 'Controller' not $routes[page_A][post] = 'Controller'.
I'm using Codeigniter framework here, I've tried to change the controller with $this->input->get('id') but it doesn't work and I don't have any idea whats really happen in my codes.
The Sender Form View code
<form action="<?= base_url().'progres_save'; ?>" method="POST">
<div class="form-group">
<div class="form-row">
<label for="idJobOrder">ID Job Order</label>
<input type="text" name="idJobOrder" class="form-control" value="<?php echo $rd[0]->kodejobglobal; ?>" readonly>
</div>
</div>
<div class="form-group">
<div class="form-row">
<a class="btn btn-primary col-xl-1 col-sm-1 mb-1 ml-auto mr-0 mr-md-2 my-0 my-md-3" href="job" id="back" role="button"><i class="fas fa-fw fa-arrow-left"></i> Back</a>
<button class="btn btn-primary btn-block col-xl-1 col-sm-1 mb-1 mr-0 mr-md-2 my-0 my-md-3">Save <i class="fa fa-fw fa-arrow-right"></i></button>
<input type="hidden" name="id" value="<?php echo $rd[0]->kodejobspesifik ?>">
</div>
</div>
</form>
The Sender Form Controller code
public function save()
{
$idglobal = $this->input->post('idJobOrder');
$data = array('jobnya' => $idglobal );
$this->Model_joborder->save_pg($data,'lapharian');
redirect('progres_material');
}
The Config Routes code
$route['progres_save']['get']='error';
$route['progres_save']['post']='save';
$route['progres_material']['get']='matused';
$route['progres_material']['post']='error';
The Recipient Form Controller code
public function matused()
{
$id = $this->input->get('id');
$data['rd'] = $this->Model_joborder->tampil2($id);
$data['fb'] = $this->Model_joborder->data_cbb();
$this->load->view('matused', $data);
}
The Recipient Form View code
<form method="POST" action="<?= base_url().'matsave'; ?>">
<div class="form-group">
<div class="form-row">
<?php if (isset($rd[0])) {?>
<input type="hidden" value="<?php echo $rd[0]->jobspesifiknya; ?>" name="idClient" class="form-control" placeholder="First name" readonly>
<?php } ?>
</div>
</div>
</form>
What I expect is the input id value from Sender will be passed and catch on Recipient form as input idClient. Can anyone her help me to find out the solution? Thank you.
You can use PHP global variable $_REQUEST to capture the data if you are not sure about the request type like this,
public function matused()
{
$id = $_REQUEST['id'];
$data['rd'] = $this->Model_joborder->tampil2($id);
$data['fb'] = $this->Model_joborder->data_cbb();
$this->load->view('matused', $data);
}
You forgot to include the id data on the redirect after the save() method is called, so you will not get anything by calling $this->input->get('id').
To solve this, pass the id data along with the redirect :
redirect('progres_material?id=' . $this->input->post('id'));
But that of course it will gives you an extra parameter on the url. If you don't want additional parameter, you could alternatively use session to pass id data while redirecting, on CodeIgniter there is a method called set_flashdata to do this :
$this->session->set_flashdata('id', $this->input->post('id'));
redirect('progres_material');
And to get the id session data on the matused() method, use the following code :
$id = !empty($this->session->flashdata('id')) ? $this->session->flashdata('id') : $this->input->get('id');
the function sumqtyin() inside codeigniter model
function sumqtyin(){
$kdbahan = $_POST['kode_bahan_baku']; //i wanna echo a value from the input text kode_bahan_baku but it always says error "undefined index kode_bahan_baku"
$datenow = date("Y-m-d");
return $this->db->query("
SELECT IFNULL(SUM(qty_in),0) AS qty_in
FROM trans_stock_movement
WHERE tanggal_movement='$datenow'
AND status_aktif='YES' AND kode_bahan_baku = '$kdbahan' ");
}
my view input text for kode_bahan_baku inside a post form
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Bahan Baku</label>
<div class="col-sm-2">
<div class="input-group">
<input type="text" class="form-control" id="nama_bahan_baku" name="nama_bahan_baku" placeholder="Bahan Baku" value="" style="width:150px" required="required">
<input type="text" id="kode_bahan_baku" name="kode_bahan_baku" value="" class="form-control">
<div class="input-group-btn">
<button type="button" class="btn btn-info btn-flat" data-toggle="modal" id="btnMenu" data-target="#menuModal">
<i class="fa fa-fw fa-search"></i>
</button>
</div>
</div>
</div>
</div>
please help :(
Your controller is the go-between of your view and your model, as such, you should be grabbing the data out using $this->input->post('kode_bahan_baku') in the controller and passing those details through to the model:
Controller:
$kdbahan = $this->input->post('kode_bahan_baku');
$dbResultObj = $this->yourLoadedModel->sumqtyin($kdbahan);
then use the object $dbResultObj like: $dbResultObj->qty_in to get out the result
Model:
function sumqtyin($kdbahan){
$datenow = date("Y-m-d");
return $this->db->select('SUM(IFNULL(qty_in,0)) AS qty_in')
->where('tanggal_movement', $datenow)
->where('status_aktif', 'YES')
->where('kode_bahan_baku', $kdbahan)
->get('trans_stock_movement')
->result();
}
Please Follow the MVC structure , Before you make any manipulation on database you just have to follow the MVC method .
VIEW => CONTROLLER => MODEL => CONTROLLER => VIEW
like #Brian Ramsey did . check out the guidelines of codeigniter
https://www.codeigniter.com/user_guide/
i'm just wanna ask again about codeigniter.
I want to make dependent select form in codeigniter with sql server database.
I have an database table name MS_UPB (it contains a location) and MS_RUANG (it contains a room in that location). My task is to show the room where the MS_RUANG.kd_lokasi (this is the room location ID) = MS_UP.kd_lokasi (this is the location ID) and show it in the dependent select box codeigniter
My Views:
<?php
echo form_open('admin/laporan/tampildbr',$att)
?>
<div class="control-group">
<label class="control-label" for="inputEmail">Unit Kerja</label>
<div class="controls">
<select name="unit" id="unit">
<?php
foreach ($isdata as $row) {
echo "<option value='".$row->KDUPB."|".$row->NAMAUPB."'>".$row->NAMAUPB."</option>";
}
?>
</select>
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputEmail">Ruangan</label>
<div class="controls">
<select name="ruangan" id="ruangan" id="ruangan_label">
<option value=""></option>
</select>
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputEmail">Jenis</label>
<div class="controls">
<input type="radio" name="jenis" value="DAFTAR BARANG RUANGAN" />Daftar Barang ruangan
</div>
<div class="controls">
<input type="radio" name="jenis" value="REKAP DBR" />Rekap DBR
</div>
</div>
<div class="control-group">
<div class="controls">
<button type="submit" class="btn btn-success" name="submit" formtarget="_blank">Kirim</button>
</div>
</div>
</form>
<p> </p>
<p> </p>
<?php form_close();?>
<script type="text/javascript">
$('#ruangan,#ruangan_label').hide();
$('#unit').change(function(){
var unit_id = $('#unit').val();
if (unit_id != ""){
var post_url = "admin/laporan/getruangan" + unit_id;
$.ajax({
type: "POST",
url: post_url,
success: function(ruangan) //what's this ruangan mean?
{
$('#ruangan').empty();
$('#ruangan, #ruangan_label').show();
$.each(ruangan,function(kd_ruang,ruang)
{
var opt = $('<option />');
opt.val(kd_ruang);
opt.text(ruang);
$('#ruangan').append(opt);
});
} //end success
}); //end AJAX
} else {
$('#ruangan').empty();
$('#ruangan, #ruangan_label').hide();
}
});
</script>
My Controller:
function getruangan($unit)
{
$unit=explode('|',$unit);
$unitkerja=$unit[0];
$this->load->model('admin/laporanmodel','',TRUE);
header('Content-Type: application/x-json; charset=utf-8');
echo (json_encode($this->laporanmodel->get_ruangan($unitkerja)));
}
My Model:
function get_ruangan($unit)
{
$this->db->select('kd_ruang,namaruang');
$this->db->from('MS_RUANG');
$this->db->where('kd_lokasi, "'.$unit.'"');
$query=$this->db->get();
$ruangan=array();
if($query->result()){
foreach ($query->result() as $ruang) {
$ruangan[$ruang->kd_ruang] = $ruang->kd_ruang;
}
return $ruangan;
} else {
return FALSE;
}
}
please help me, thanks for your help :)
I think you have issue while appending the value to your select box.
I would tell you to do all required stuff in model itself. If you do so, we can reduce execution time of one for loop
Try changing in your model like this.
In Model
if($query->result()){
$option = "<option>Select the value</option>";// this is for default value.
foreach ($query->result() as $ruang) {
$ruangan[$ruang->kd_ruang] = $ruang->kd_ruang;
$option .= "<option value='$ruang->kd_ruang'>{$ruang->kd_ruang}</option>".
}
return $option;
} else {
return FALSE;
}
In model only we are generating required html for our view.
In Controller
//header('Content-Type: application/x-json; charset=utf-8');// comment this line
echo ($this->laporanmodel->get_ruangan($unitkerja));
I have removed json part in controller. We will take plain text here.
In view
Im changing entire success() in ajax,
success: function(ruangan) //what's this ruangan mean?
{
$('#ruangan').append(ruangan);// just append the value coming from ajax call here.
}
We have reduced execution time of one loop.
Hope it helps.
I am currently trying to create a sample shopping site,The problem came when I created a search page.In my search page I Have two fields one for enter the keyword and other for select type of item
Which means search,keyword in the selected item.but the item defined in DB is 0 and 1 and i Trying to get it my code but fails...could any one help me...
The Gfunction code is
public static function item(){
$optionList='';
$CategoryList = OfferEvents::model()->findAllByAttributes(array());
foreach($CategoryList as $catdata)
{ $optionList.="<option value='".$catdata['type']."'>".$catdata['name']."</option>"; }
return $optionList;
}
and view code is
<form action="<?php echo Yii::app()->baseUrl; ?>/offer?>" method="GET" class="form-inline form-section-2 row fadeInDown animated">
<div class="col-sm-5 form-group">
<input type="text" name="search" class="form-control" id="search" value="" placeholder="Enter Your Keyword">
</div>
<div class="col-sm-4 form-group">
<select name="cat" class="form-control selectpicker">
<option value='0'>Select type</option>
<?php echo GFunctions::item(); ?>
</select>
</div>
<div class="col-sm-3 form-group">
<button type="submit" class="btn btn-default btn-new">Search</button>
</div>
</form>
why don't you use Yii built in functions to handle the dropdown?
I am not sure how your Models looks like but you can choose one of the following functions to achieve what you want instead of trying to return a String $optionList with HTML tags.
CHtml::activeDropDownList() // for directly bind to active record model
CHtml::dropDownList()
Try this code....
Function
public static function item(){
$CategoryList = OfferEvents::model()->findAllByAttributes(array());
$optionList = CHtml::listData($countries, 'type', 'name')
return $optionList;
}
In view
<?php echo CHtml::dropDownList('cat', '', GFunctions::item(), array('prompt'=>'Select type'));?>