I implemented my project in Yii. i done URL management its working fine. but i search URL is not being proper. i added my code here. please tell me how to change this code according to my URL..
my main.php:
<form class="navbar-form " role="search" name="searchform" method="POST" action="<?php echo Yii::app()->baseUrl.'/index.php/recipe/course1/';?>" id="menu-form-style" onsubmit="return ValidateSearchForm();">
<div class="form-group">
<input type="text" name="search" id="search" placeholder="Quick Search...." class="form-control" onkeyup="lookup(this.value);" onblur="fill();">
i sent to my recipe controller.
where i did like this: recipe controller
public function actionCourse1(){
if(isset($_POST["search"]))
$course=$_POST["search"];
$this->redirect(array('recipe/course','searched'=>$course));}
public function actionCourse(){
$model=new Recipe;
if(isset($_GET['searched']))
$count=$_GET['searched'];
$bigArray=array();
in my configure main.php
'searched'=>'recipe/course',
above config line i wants to be show.
but am getting like this
search/searched/asdfadfadfa
http://kitchenking.ebhasin.com/
this our website. please suggest me suitable answer
if i understod your question true try this...
$this->render('/recipe/course/ or your file place', array('searched'=>$course));}
or
$this->redirect('/recipe/course/searched/'.$course);
Re-read http://www.yiiframework.com/doc/guide/1.1/en/topics.url this one, yes I know that is not an answer, but I think your routes is invalid.
change your config main.php:
'search/<searched>'=>'recipe/course',
Related
I'm new to laravel and still learning about this framework.
I already found some questions on stackoverflow but it still didn't work out for me.
My problem is:
I got this
localhost/codehub/public/users/create
and the route:
Route::get('users/create',['uses' => 'UserController#create']);
Inside the page there's some form like this:
so when I click create button it is supposed to route it into store function in the user controller
Route::post('users',['uses' => 'UserController#store']);
public function store(Request $request)
{
return $request->all();
}
so the problem is when I click that create button it always redirects me to localhost/users and because of that, I can't process my store function.
Any advice?
this is my form code:
<form method="post" action="/users">
<input type="text" name="name">
<input type="email" name="email">
<input type="password" name="password">
<input type="submit" value="Create">
</form>
The problem may be because of relative path in form action.
You should always use named routes which allow the convenient way of generation of URLs or redirects for specific routes.
So you can change your route as:
Route::post('users', 'UserController#store')->name('users.create');
And in form you can write as:
<form method="post" action="{{ route('users.create') }}">
I'm having a very frustrating (super-newbie) experience with Laravel 5.1.
Sure there must be something that I'm missing, but unfortunately I couldn't find anything on Laravel docs.
The problem is this (and I believe is even relatively simple): while all GET routes are working, the routes in POST are 'rerouting' me to the wrong place.
For instance, assuming that the controller is this:
namespace App\Http\Controllers;
use Illuminate\Routing\Controller as BaseController;
use View;
class PagesController extends BaseController {
public function hello(){
return view('hello');
}
public function register(){
//Registration rules
$inputData=array(
'name' => \Input::get('name'),
'email' =>\Input::get('email'),
'password' => bcrypt(\Input::get('password')),
);
createUser($inputData);
return view('stat');
}
private function createUser($inputData){
return User::create($inputData);
}
}
and given the route:
Route::get('/','PagesController#hello');
this one redirects me correctly to the view specified in the controller,at the method indicated.
A POST operation cannot be successfully performed, since
Route::post('/','PagesController#register');
with the form having:
<form action="/" method="post">
<input type="hidden" name="_token" value="<?php echo csrf_token(); ?>">
<label for="name">User Name</label><br/>
<input type="text" name="name" id="name"/><br/>
<label for="name">E-mail</label><br/>
<input type="text" name="email" id="email"/><br/>
<label for="password">password</label><br/>
<input type="password" name="password" id="password"/><br/>
<input type="submit" value="auth!"/>
</form>
results in redirecting me to xampp home page.
For example, the "main registration page" is at this url:
http://localhost:8080/laravel/project1/public/
(GET OK)
and when I click on the submit button, I'm sent to
http://localhost:8080/
Just few more indicators for you to try and help me (I'm genuinely stuck):
1) I didn't use a VirtualHost (searched on the web, but had always no luck in configuring apache properly...good luck I've got xampp)
2) The page "hello" has a link that I used as a test:
Link
and it redirects me correctly to the sought-after
http://localhost:8080/laravel/project1/public/stat
3)In the POST method, I've used a dd($inputData) to see what was going wrong, and as a result I had...nothing. Not a blank page,just always the localhost page. This led me to think that somehow the controller method isn't called, since no dd(---) result got in page.
Hope someone can help.
Many thanks
Your domain is http://localhost:8080 , so when you set action to '/' , it goes to root. It`s not good practice , but your solution is to change :
<form action="/laravel/project1/public/" method="post">
I`d create a virtual host for the project in apache , so document root would be /laravel/project1/public/ .
you are posting your form to the root / that is why you are being routed to xampp page. To solve this problem, change your form action to this
<form action="/post/my/form" method="post">
in your routes
Route::post('/post/my/form','PagesController#register');
I have a search page which is queried from index.php
example : http://localhost/sgc/admin/index.php?page=search
then i created a form within this page to search users by names
<form role="form" method="get" action="" class="form-horizontal">
<input type="search" name="name" class="form-control" placeholder="username">
</form>
the problem is when the input is submitted it redirects to the index.php and adding the paramteres to the index page http://localhost/sgc/admin/index.php?name=
required URL format is to be http://localhost/sgc/admin/index.php?page=search&name=
can it be achived using php or i have to use javascript
Thanks, and sorry for my bad english :)
try :
After submision :
your url : ttp://localhost/sgc/admin/index.php?page=search&name=YOUR_STRING
<form id="search" action="/app_name/index.php/index/search" method="post">
I've noticed that when specifying a link in php, you don't have to specify application name:
echo form_open('index/function');
Is it possible to avoid specifying application name in html form action?
Sorry if this question is a duplicate.
set base url in config.php
$config['base_url'] = 'http://localhost/codeigniter/';
and use it like below
<form id="search" action="<?php echo base_url(); ?>index/search" method="post">
OR
<form id="search" action="<?php echo $this->config->base_url(); ?>index/search" method="post">
you need to load url helper in autoload or in controller
$this->load->helper('url');
Right now I have those.
user_add.blade.php
<form method="post" id="customForm" action="admin/user_add">
...
</form>
routes.php
Route::post('admin/user_add', 'admin#user_add');
admin.php
public function action_user_add()
{
print_r(Input::get());
}
How should I give the correct action path? Like; admin/user_add or something like {{ Base_path }}admin/user_add? I don't want issues when I move into production server. (e.g using subfolders etc.)
Also, is my approach correct or are there better ways?
Ps. Should I use Form methods? Like <input type="text" id="username" name="username" class="small"> to Form:text("username", "", "small");
Try this:
<form method="post" id="customForm" action="{{ URL::to_action('admin#user_add') }}">
Whether you want to use the form helpers or not, is really your choice. They make some things simpler, for example declaring the target URL, but they're a little cumbersome for writing additional HTML like you did (adding an id attribute to the form).