How to get data by selecting the drop-down in CodeIgniter.
Below is my code it does not work. The below code is not working properly when I selecting an option in the drop down and when I submit page appearing empty. when click please help me to get data. I am doing it in CodeIgniter. I want to get data from the database . I think the code is perfect am new to CodeIgniter the below code is not working properly the page appearing empty when click please help me to get data. I am doing it in CodeIgniter. I want to get data from the database . I think the code is perfect am new to CodeIgniter.
view:
<?php echo form_open('super_admin/believers_controller/view_believerr/' , array('class' => 'form-horizontal validatable', 'enctype' => 'multipart/form-data') ); ?>
<div class="form-group">
<label class="col-sm-3 control-label no-padding-right" for="form-field-1"> District Id</label>
<div class="col-sm-9">
<select name="report_type" >
<option >Select Id</option>
<option value="believers">Believers</option>
<option value="staff">staff</option>
<option value="staff">committe members</option>
</select>
</div>
</div>
<div class="clearfix form-actions">
<div class="col-md-offset-3 col-md-9">
<input type="submit" name="Submit" class="btn btn-info" >
controller:
<?php
function view_believerr()
{
$report_type = $this->input->get('report_type');
if($report_type=='believers'){
$this->load->model('believers/believers_model');
$page_data['h']=$this->believers_model->view_believer();
$page_data['page_name'] = 'believers/view_believer';
$this->load->view('index', $page_data);
}
}
?>
model:
<?php
function view_believer()
{
$query = $this->db->get('tbl_believers');
return $query;
}
?>
I want to get data from database . I think the code is perfect am new to codeigniter the below code is not working properly the page appearing empty when click please help me to get data. I am doing it in codeigniter. I want to get data from database . I think the code is perfect am new to codeignite
Use $this->input->post('report_type');
Related
I am creating a report of users in which I use different type of filters but how can I get pdf of filtered data only .I use,
composer require barryvdh/laravel-dompdf
my controller
function pdf()
{
$pdf = \App::make('dompdf.wrapper');
$pdf->loadHTML($this->convert_customer_data_to_html());
return $pdf->stream();
}
but in above code I get all data from database, but my basic view have different type of filters like that
1-select from option
<div class="col-md-3 p-0" style="margin-bottom:35px">
<select class="select-items" id="report_type">
<option value="rider">user</option>
<option value="driver">Driver</option>
</select>
</div>
2-autocomplete
<div class="col-md-3 p-0" style="margin-bottom:35px">
<input type="text" id="myInput" onchange="SearchName()" onkeyup="SearchName()">
<div id="List"></div>
</div>
3-another dropdown like no 1
all the filters are working good on view ,but my question is that how will I get pdf of filtered data only
I'm working on a reporting page using php Laravel framework. I select the options from the comboboxes, these values are sent to the controller to replace them in some queries used to display the reports.
When I click the submit button, the page refreshes and the name shown is the last element of the dropdown.
My Controller:
$negocioDive = DB::table('ma_leads_reporte')
->selectRaw('NEGOCIO, year(FEC_CREACION) as AÑO')
->groupBy('NEGOCIO', 'AÑO')
->get()->toArray();
$selectFecha = DB::table('param_fecha')
->selectRaw('mesNum, mesNom')
->groupBy('mesNum', 'mesNom')
->get()->toArray();
$año = $request ->input('año');
$mes = $request -> input('mes');
$negocio = $request -> input('negocio');
//Solicitud de Cotización versus mes anterior
$mesAnt = DB::table('ma_leads_reporte')
->selectRaw('count(*) as C, day(FEC_CREACION) AS DIA, monthname(FEC_CREACION) AS MES')
->whereMonth('date_identified', '=', $mes-1)
->whereYear('date_identified', '=', $año)
->groupBy('MES', 'DIA')
->get()->toArray();
$vscont = array_column($mesAnt, 'C');
$antMes = array_column($mesAnt, 'MES');
$dia = array_column($mesAnt, 'DIA');
My View:
<div class="container">
<div class="row justify-content-center">
<div class="content mt-3">
<div class="animated fadeIn">
<div class="col-lg-8">
<div class="card">
<div class="card-header">
<form action="{{route('reportes')}}" method="GET" id="fecha">
{{Form::label('', 'Año')}}
<select id="año" name="año">
#foreach($negocioDive as
$negocioD)
<option value="{{$negocioD->AÑO}}"
selected="selected">{{$negocioD->AÑO}}</option>
#endforeach
</select>
{{Form::label('', 'Mes')}}
<select id="mes" name="mes">
#foreach($selectFecha as $fecha)
<option value="{{$fecha->mesNum}}" name="{{$fecha->mesNom}}">{{$fecha->mesNom}}</option>
#endforeach
</select>
{{Form::label('', 'Negocio')}}
<select id="negocio" name="negocio" >
#foreach($negocioDive as $negocioD)
<option value="{{$negocioD->NEGOCIO}}" selected="selected">{{$negocioD->NEGOCIO}}</option>
#endforeach
</select>
<button type="submit"class="btn btn-default" id="filter">Filtrar
<i class="fa fa-filter"></i>
</button>
</form>
<?php if(isset($_GET['año']) && isset($_GET['mes']) && isset($_GET['negocio'])){
echo "<h4> Año: $año | Mes: {$fecha->mesNom} | Negocio: $negocio </h4>";
}?><!--
<p id="mesJS"></p> -->
</div>
</div>
</div>
After receiving the request variables, it should show the correct values instead of the last index of the dropdown.
What can I do?
dropdown options:
After submit:
The reason it is showing the last index of the dropdown is that you are looping on your various items and creating your options within each select box with 'selected' overwritten every time all the way to the last one in the loop.
To fix this, you'll need to add some type of conditional on the option box to tell it if the loop item is the correct selected one. If the new model has the key within this loop, then, and only then, make it selected. Something like this (You'll need to make this code your own):
#foreach($negocioDive as $id=>name)
<option value="{{$id}}" {{$theThingYouAreSelecting->id === $id?"selected":''}}>$name</option>
#endforeach
NOTE - I'm assuming you are sending a key->value array to the foreach as this is what the option expects - the key would be the id and the value would be the name for the item.
Once you get this working, I strongly recommend looking at LaravelCollective HTML - it binds the model to the form and automates a huge chunk of the conditionals.
I'm currently new on Laravel and trying to develop my first project. I have this MethodNotAllowedHttpException in RouteCollection.php line 218 error during my development for inserting data into database. I have searched both Google & Stackoverflow for solutions but non are related to my current problem and some of them way too complex for this simple problem (I think so...).
I have my form in my checklist page:-
<form action="{{url('addchecklist')}}" method="POST">
{{ csrf_field() }}
<div class="row">
<div class="col-sm-12">
<div class="text-left">
<input type="hidden" name="schmFK" value="{{$id}}">
<div class="col-sm-6">
<h4>
<label>Section</label>
<select class="selectpicker form-control" data-live-search="true" name="sctionPK">
<option selected>Select the Section</option>
#foreach ($sction as $key=>$slct1)
<option value="{{$slct1->ssctionPK}}">{{strtoupper($slct1->ssctionName)}}</option>
#endforeach
</select>
</h4>
</div>
<div class="col-sm-2">
<button type="button" data-toggle="modal" data-target=".bs-example-modal-lg" class="btn btn-primary btn-sm" style="margin-top:33px; padding-top:7px; padding-bottom:7px;">Add Section</button>
</div>
<div class="col-sm-4">
<h4>
<label>Severity</label>
<select class="selectpicker form-control" name="svrityPK">
<option selected>Select the Severity</option>
#foreach ($svrity as $key=>$slct2)
<option value="{{$slct2->severityPK}}">{{strtoupper($slct2->severityName)}}</option>
#endforeach
</select>
</h4>
</div>
<div class="col-sm-12">
<h4>
<label>Question</label>
<input class="form-control" type="text" placeholder="Question" name="question">
</h4>
</div>
<div class="col-sm-6">
#include('widgets.button', array('class'=>'primary btnaddstd', 'size'=>'lg', 'type'=>'submit', 'value'=>'Add Checklist'))
</div>
</div>
</div>
</div>
</form>
Then I have this route for inserting data from the form into database:-
Route::post('/addchecklist', function (Request $request){
// Create instance to store record
$scheme = new App\checklists;
$scheme->schmFK = $request->schmFK;
$scheme->schSectionFK = $request->sctionPK;
$scheme->severityFK = $request->svrityPK;
$scheme->clQuestion = $request->question;
$scheme->save(); // save the input
// Sort all records descending to retrieve the newest added record
$input = App\checklists::orderBy('cklistPK','desc')->first();
// Set search field variable default value of null
$src = isset($src) ? $src : null;
// Get Checklist reference from cklists_stddetails with the designated ID
$chkstd = App\Cklists_stddetail::where('cklistFK', $input->cklistPK)
->join('stddetails', 'stdDtlFK', '=', 'stddetails.sdtlPK')
->get();
// Get the newest stored record
$chcklst = App\checklists::where('cklistPK', $input->cklistPK)->firstOrFail();
// Get all data from table 'stddetails'
$stddetail = App\stddetails::all();
// Get all data from table 'standards'
$stndrd = App\standard::all();
// Get all data from table 'sections'
$sction = App\Section::all();
// Redirect to 'addref.blade' page with the newest added record
return redirect('addref/'.$input->cklistPK)
->with('src', $src)
->with('chkstd', $chkstd)
->with('id',$input->cklistPK)
->with('schmid', $request->schmFK)
->with('chcklst', $chcklst)
->with('stddetail', $stddetail)
->with('stndrd', $stndrd)
->with('sction', $sction);
});
My scenario is this, I have a form for user to input data in it. Then when the data is saved, they will be redirected to the page of that data to do something there. The data is successfully saved in the database but the redirection to the designated page (addref.blade) with the newest record ID return error:-
But the URL goes where I wanted it to go (means the URL is right):-
As you can see, the usual solution from the net that I found are:-
Make sure both method from routes and the form is the same, and mine it is:-
method="POST"
Route::post
Make sure the URL routes can recognize the form's action URL, and mine it is:-
<form action="{{url('addchecklist')}}" method="POST">
Route::post('/addchecklist', function (Request $request)
Include CSRF token field in the form, and mine it have been included:-
<form action="{{url('addchecklist')}}" method="POST">
{{ csrf_field() }}
I have tried those simple solution provided on the net and nothing is helpful enough. I'm still wondering what else I have missed and hoped that anyone here can assist on solving my issue.
I think the error is that you have a redirect which you have not registered in your routes or web.php file.
Sample redirect:
Route::post('/addchecklist', function (Request $request){
//some post process here...
return redirect('addref/'.$input->cklistPK)
->with('src', $src)
->with('chkstd', $chkstd)
->with('id',$input->cklistPK)
->with('schmid', $request->schmFK)
->with('chcklst', $chcklst)
->with('stddetail', $stddetail)
->with('stndrd', $stndrd)
->with('sction', $sction);
});
Route::get('addref/{id}', function(Request $request){
//show the blade.php with data
});
Can you please write :
url('/addchecklist')
instead of :
url('addchecklist')
and then print_r('in');
and die; and check what you get.
Route::post('/addchecklist', function (Request $request){
print_r('in');
die;
});
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
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'));?>