Here I ant desired url like in php but how can I code this in codeigniter with controller, model, and view? someone has a code with this?
http://mysite.com/search?query=batman&cat=movie
My Controller
function index(){
//some code to get search query value
}
My Model
function getSearch(){
//some code to get search value
}
My View
<form action="http://mysite.com/search/'; ?>">
<input name="query" value="">
<input name="cat" value="">
<input type="submit">
</form>
I want also to retrieve the seesion in text field after submitting.
You should specify the method of the form
e.g.
<form action="http://mysite.com/search/" method="post">
use this to fetch the record
$query = $this->input->post('query');
$cat = $this->input->post('cat');
In order to retrieve the type text in to the text field, use set_value
e.g.
<input name="query" value="<?php set_value('cat') ?>">
<input name="cat" value="<?php set_value('query') ?>">
hope this helps!
Related
I have a multi-column search form inside the 'users.index' view. The form is as mentioned below:
<form method="get" action="{{route('search')}}">
<input autocomplete="off" type="text" name="name">
<input autocomplete="off" type="text" name="role">
<select name="status">
<option disabled selected>--</option>
<option value="0">inactive</option>
<option value="1">active</option>
</select>
<button type="submit">search</button>
</form>
And the route is this:
Route::get('/admin/users/search', 'Admin\Search\SearchUsersController#search')->name('search');
But whatever I write inside the search function of the controller, it returns nothing and redirects me to a blank page!
Let 's imagine the controller is something like this :
class SearchUsersController extends Controller
{
public function search(Request $request)
{
dd($request->all());
}
}
I wonder why such a thing is happening. When I change the method of the form into Post and I determine two different routes, the problem is solved but it 's a search form and logically the method should be get.
You need to use csrf_field() or <input type="hidden" name="_token" value="'.csrf_token().'"> in your form.
Eventually I found a solution. If you have resource routes in web.php file of your project, you should introduce new routes before resource ones.
I'm using Laravel 5. I have a function in my Controller, which use some of my params. This params I save in my view, while the user enters them in the input. And I need this data to transfer to my controller. Is it possible? Maybe anybody has had the same problem, I hope You can help.
Thank You!
Here is my controller:
$databaseLogin = new DatabaseController();
$dbRequest = $databaseLogin->loginReq($login, $passwd);
return view('login');
And here is my view:
<input class="form-control input-lg" type="text" id="login" name="login" placeholder="Login">
<input type="password" name="passwd" id="pass" autocomplete="off" class="form-control input-lg" placeholder="Password">
You can do if from post request
1.First create a route
Route::POST('your route’, 'yourController#add');
2.Then create a form with csrf token in view
<form action="{{url(‘your route’)}}" method="post">
{{csrf_field()}}
<input type=”text” name=”username”>
<input type=”text” name=”password”>
<input type=”submit” value=”login”>
</form>
3.Then you can get the values in your controller
Public function add(Request $request){
$name = $request.username;
$password= $request.password;
//code continues
}
I tried store data in a session using CI in my register function.
public function register(){
$firstname = $this->input->post('firstname');
$email= $this->input->post('email');
$dev_info = array('fname'=>$firstname, 'eaddress'=>$email);
$this->session->set_userdata($dev_info);
}
and in my other function verification I want to get the session data and pass to the view
public function verification(){
$data['fname'] = $this->session->userdata('fname');
$data['eaddress'] = $this->session->userdata('eaddress');
$this->load->view('index', $data);
}
and I want to save its value in input type
in the view
<input type="hidden" id="firstname" value="<?php echo $fname?>">
<input type="hidden" id="email" value="<?php echo $eaddress?>">
but i am having a hard time saving its value in an input everytime I check using view source. Please help!
you can get session variables one by one also
$first_name = $this->session->userdata('fname');
$email_address = $this->session->userdata('eaddress');
in view you can use these variables or you can write code for view like this
<input type="hidden" id="firstname" value="<?php echo $this->session->userdata('eaddress'); ?>">
<input type="hidden" id="email" value="<?php echo $this->session->userdata('fname')?>">
in controller create session for ur input data
$data['fname'] = $this->session->userdata('fname');
$data['eaddress'] = $this->session->userdata('eaddress');
in view retrieve the input data from the session by adding the value by set_value
<input type="hidden" id="firstname" value="<?php echo set_value('fname'); ?>">
<input type="hidden" id="email" value="<?php echo set_value('eaddress'); ?>">
When I am creating a new entry and leave at least one field to error out then submit the form, upon validation the field values are blank.
Is there a way to return the values to their corresponding field when submitting? Something similar to CodeIgniter's set_value()?
On your form html, set the default value to
old('field_name')
Example if you are using laravel's blade:
<input class="form-control" name="name" type="text" value="{{ old('name') }}" id="name">
Example without blade:
<input class="form-control" name="name" type="text" value="<?php echo old('name'); ?>" id="name">
You can also use:
Input::old('field_name')
I have a componenet in joomla 2.5.
I have several view, in one of then I have a combobox, when I click on it, I want to call a function for that I have this
<form class="product_filter" action="<?php echo JURI::root()?>index.php/com_productos/buscarCategoria" method="POST">
<input type="hidden" class="type" name="type" value="HEALTH_FOOD"/>
<div class="select_wrapper small first">
<?php echo JHTML::_('select.genericlist', $nameCombo,'name','onChange="this.form.submit()"','value','text'); ?>
</div>
the name of my component is com_productos so in the producto.php I have this
class ProductosController extends JController
{
function buscarCategoria(){
$jinput = JFactory::getApplication()->input;
$view = $jinput->getCmd('view', 'productos');
JFactory::getApplication()->input->set('view', $view);
$model = &$this->getModel($view);
$view = &$this->getView($view, 'html');
$view->setModel($model, true);
$view->categoria();
}
but never execute this function.
Any idea
You should pass task (and controller as part of it) in the hidden field like this:
<input type="hidden" name="task" value="productos.buscarCategoria"/>
And your action can be simply index.php.
Finally I solved the problem
<input type="hidden" name="controller" value="field" />
<input type="hidden" name="option" value="com_productos" />
<input type="hidden" name="task" value="buscarCategoria" />
</form>