i want to pre fill my html form field "Reference" from url value for referne is afer ref?=1234 how to do it with laravel
<form method="post" accept-charset="utf-8" class="block" enctype="multipart/form-data" action="{{ route('register') }}">
{!! csrf_field() !!}
<div class="row">
<div class="col-md-12 col-sm-12">
<div style="width: 100%" class="alert alert-warning">
Please Register With a Reference User.
</div>
</div>
</div>
<div class="input-group">
<input type="text" name="reference" value="HERE WANT TO SHOW REFEERENCE CODE FROM URL" required class="form-control" placeholder="Enter Reference ID *" aria-describedby="basic-addon1">
<span class="input-group-addon" id="basic-addon1"><i class="fa fa-handshake-o"></i></span>
</div>
You can use like:
<input type="text" name="reference" value="{{ app('request')->input('ref') }}" required class="form-control" placeholder="Enter Reference ID *" aria-describedby="basic-addon1">
Use request() helper:
$ref = request('ref'); // It will return 1234.
There isn't a $GET variable in PHP.
There is a $_GET.
In laravel, you may use the Request facade or Input facade
so here:
<input value="view{{ \Request::get('ref') }}" type="text" name="reference" required class="form-control" placeholder="Enter Reference ID *" aria-describedby="basic-addon1">
// http://localhost/codec/register?ref=g5M089zQeVzc
// will produce
// <input value="viewg5M089zQeVzc" ...
Related
I'm new with laravel and now i making some small project. I have a form, after the submit button pressed i got this error message "Sorry, the page you are looking for could not be found."
Is there anything wrong about my code?
Please help me to fix this issue, so i can continuing the project.
Thanks in advice
view blade, i named it index.blade.php
<div class="col m7 s12">
<form method="submit" action="post">
{{ csrf_field() }}
<div class="card-panel">
<h5>Please Fill Out This Form</h5>
<div class="input-field">
<input type="text" name="name" id="name" required class="validate">
<label for="name">Name</label>
</div>
<div class="input-field">
<input type="email" name="email" id="email" class="validate">
<label for="email">Email</label>
</div>
<div class="input-field">
<input type="text" name="phone" id="phone">
<label for="phone">Phone</label>
</div>
<div class="input-field">
<textarea name="message" id="message" class="materialize-textarea"></textarea>
<label for="message">Message</label>
</div>
<button type="submit" class="btn" blue darken-1>Send</button>
</div>
</form>
controller, i named it LayoutController
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use DB;
class LayoutController extends Controller
{
/**
* Display a listing of the resource.
*
* #return \Illuminate\Http\Response
*/
public function index()
{
//
return view('layouts/index');
}
public function submit(Request $request)
{
$name = $req->input('name');
$email = $req->input('email');
$phone = $req->input('phone');
$message = $req->input('message');
$data = array('name'=>$name,"email"=>$email,"phone"=>$phone,"message"=>$message);
$data->save();
return Redirect::to('/layouts/index');
}
routes web.php
Route::get('/', 'LayoutController#index');
Route::post('/submit', 'LayoutController#submit');
Your form method should be POST and action should be /submit
<form method="POST" action="/submit">
{{ csrf_field() }}
<div class="card-panel">
<h5>Please Fill Out This Form</h5>
<div class="input-field">
<input type="text" name="name" id="name" required class="validate">
<label for="name">Name</label>
</div>
<div class="input-field">
<input type="email" name="email" id="email" class="validate">
<label for="email">Email</label>
</div>
<div class="input-field">
<input type="text" name="phone" id="phone">
<label for="phone">Phone</label>
</div>
<div class="input-field">
<textarea name="message" id="message" class="materialize-textarea"></textarea>
<label for="message">Message</label>
</div>
<button type="submit" class="btn" blue darken-1>Send</button>
</div>
</form>
Try this :
<form method="POST" action="{{ route('submit') }}">
The Error you're getting is because the wrong <form> tag attributes
action => 'The route or page or class method that'll process the form
information'
method => 'This the URI HTTP verb used to transport information, you
can either use POST(sending data as http payload) or GET(sending data
as query string)
changing the <form> tag like this will solve your issue
<form method="POST" action="{{ url('/submit') }}">
The form method should be POST and the action will be your route:
<form method="POST" action="{{ url('/submit') }}">
<div class="col m7 s12">
<form method="POST" action="{{url('/submit')}}">
{{ csrf_field() }}
<div class="card-panel">
<h5>Please Fill Out This Form</h5>
<div class="input-field">
<input type="text" name="name" id="name" required class="validate">
<label for="name">Name</label>
</div>
<div class="input-field">
<input type="email" name="email" id="email" class="validate">
<label for="email">Email</label>
</div>
<div class="input-field">
<input type="text" name="phone" id="phone">
<label for="phone">Phone</label>
</div>
<div class="input-field">
<textarea name="message" id="message" class="materialize-textarea"></textarea>
<label for="message">Message</label>
</div>
<button type="submit" class="btn" blue darken-1>Send</button>
</div>
</form>
I'm trying to figure out how to properly set URL parameters to auto fill form fields in laravel
The form works and properly submits data but I have a URL like testsite.com/register?email=email#test.com&password=dK94*DFj
and I'd like to auto fill the form with the email and password from the URL
the form:
<form method="POST" action="{{ route('auth.register') }}">
<div class="reg-card reg-margin-bottom">
<div class="reg-card-content">
<div class="form-group">
<label for="email">Email Address</label>
<input type="email" class="form-control" id="email" name="email" required value="{{ $invitation->email }}" />
</div>
<div class="form-group">
<label for="password">New Password</label>
<input type="password" id="password" class="form-control" required name="password" />
</div>
</div>
</div>
<div class="reg-card">
<div class="reg-card-content">
<button type="submit" class="btn btn-primary btn-block">Create account</button>
</div>
</div>
</form>
Can I set this so that, as long as the params exist in the URL, then they autofill and disable those fields?
You can get it by using
{{ request()->email }} and {{ request()->password }}
However, passing password in the url is no a good idea though!
if you want a cleaner URL, uou can create a route for the URl register.
Route::get('/register/{email?}/{hash?}',function($email,$hash){
return view("viewFile",['email'=>$email,'password'=>$hash]);
});
In your view
<form method="POST" action="{{ route('auth.register') }}">
<div class="reg-card reg-margin-bottom">
<div class="reg-card-content">
<div class="form-group">
<label for="email">Email Address</label>
<input type="email" class="form-control" id="email" name="email" required value="{{ $email }}" />
</div>
<div class="form-group">
<label for="password">New Password</label>
<input type="password" id="password" class="form-control" required name="password" value="{{$password}}" />
</div>
</div>
</div>
<div class="reg-card">
<div class="reg-card-content">
<button type="submit" class="btn btn-primary btn-block">Create account</button>
</div>
</div>
</form>
I don't recommend you to pass a password in the url, but if it is a hash to validate that the email is the correct one, is a good idea I do it when I want to verified that the info is not changed by the user. Also this will need to hash the email and compare the hash with the one on the url.
I have just created a new project in larvel and I am trying to submit form in db but it is not saving data in db.
here is my form
<form id="" method="post" class="form-horizontal" action="{{ route('updateadminprofile')}}"enctype="multipart/form-data" >
#if (Session::has('success'))
<div class="alert alert-success" role="alert" style="font-size: 18px;">
<strong>Success: </strong>
{{ Session::get('success') }}
</div>
#endif
<div class="form-group">
<label class="col-sm-4 control-label" for="userName"> Name</label>
<div class="col-sm-5">
<input type="text" class="form-control" id="name" name="name" placeholder="name}" value="name" />
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label" for="userName"> Description</label>
<div class="col-sm-5">
<input type="text" class="form-control" id="description" name="description" placeholder="Description}" value="description" />
</div>
</div>
<button style="margin-left: 30%" type="submit" class="btn btn-primary" name="signup" value="sumbmit" >Save</button>
My route is
Route::group(['namespace' => 'PrivatePages'], function () {
Route::any('/updateadminprofile', ['as' => 'updateadminprofile',
'uses' => 'ProductController#UpdateAdminProfile']);
});
here is my contoller function
public function UpdateAdminProfile(CreateProductRequest $request)
{
$saveproduct = new Product();
$saveproduct->name = $request->name;
$saveproduct->description = $request->description;
$saveproduct->save();
}
it is not saving record in db. and when i try to submit form it gives me below text,
The page has expired due to inactivity.
Please refresh and try again.
when i added csrf in form it even not going to route specified in the action of form
Try this, you are probably missing the CSRF field in your form. Also keep the Flash message out of your form.
#if (Session::has('success'))
<div class="alert alert-success" role="alert" style="font-size: 18px;">
<strong>Success: </strong>
{{ Session::get('success') }}
</div>
#endif
<form id="form" method="post" class="form-horizontal" action="/updateadminprofile">
{{ csrf_field() }}
<div class="form-group">
<label class="col-sm-4 control-label" for="name"> Name</label>
<div class="col-sm-5">
<input type="text" class="form-control" id="name" name="name" placeholder="name" value="name" />
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label" for="description"> Description</label>
<div class="col-sm-5">
<input type="text" class="form-control" id="description" name="description" placeholder="Description}" value="description" />
</div>
</div>
<button style="margin-left: 30%" type="submit" class="btn btn-primary" name="signup" value="submit">Save</button>
</form>
Edit: cleaned up some minor HTML errors and specified the route directly instead of a blade function. Could you try this?
I solved the issue by just adding following namespaces in the CreateProductRequest and ProductController
In Create CreateProductRequest updated following lines.
use Illuminate\Support\Facades\Request;
class CreateProductRequest extends Request{}
In Product Controller i use following namespace
.
use App\Http\Requests\CreateProductRequest;
Thanks All for your time and help
When I attempt to capture the template name in a form input value parameter it results in an empty value. I'm hoping this is just because I need to escape something. Outputting this.page.id in the body outside of an input tag works fine, and even inside of the tag as long as I'm not setting equal to the value it outputs correctly. How do I get the value to equal the output of the page name?
<form id="fcia_gen-contact_form" class="row" data-form-redirect="application/" data-form-type="core-4-redirect">
<div class="col-md-6">
<input type="text" name="first" class="col-md-12">
<label>First Name</label>
</div>
<div class="col-md-6">
<input type="text" name="last" class="col-md-12">
<label>Last Name</label>
</div>
<div class="col-md-6">
<input type="email" name="email" class="col-md-12">
<label>Email</label>
</div>
<div class="col-md-6">
<input type="tel" name="phone" class="col-md-12">
<label>Phone Number</label>
</div>
{{ this.page.id }}
<input type="hidden" name="Page_Type" value="{{ template_type }}">
<input type="hidden" name="Page" value="{{ this.page.id }}">
</form>
update: It looks like it's the equal sign causing this.
I've also tried string interpolation, which results in the same:
<input type="hidden" name="Page" {{ "value=\"#{this.page.id}\"" }}>
I'm trying register users in a laravel 5 application using the restful controller.
The problem is that when I dump the data in my store function, I only get the csrf token, but not the values.
Here's what I tried so far:
Input::all();
Request::get();
Here's the code I'm executing:
Form
<form class="form-horizontal" method="post" action="/users">
<div class="form-group">
<label for="name" class="col-lg-2 control-label">
Name
</label>
<div class="col-lg-10">
<input type="text" class="form-control" id="name" value="a">
</div>
</div>
<div class="form-group">
<label for="email" class="col-lg-2 control-label">
Email
</label>
<div class="col-lg-10">
<input type="email" class="form-control" id="email" value="a#a.Fr">
</div>
</div>
<div class="form-group">
<label for="password" class="col-lg-2 control-label">
Pw
</label>
<div class="col-lg-10">
<input type="password" class="form-control" id="password">
</div>
</div>
<div class="form-group">
<div class="col-lg-10 col-lg-offset-2">
<button type="reset" class="btn btn-default">Cancel</button>
<button type="submit" class="btn btn-primary">Create</button>
</div>
</div>
<input type="hidden" name="_token" value="{{ csrf_token() }}">
</form>
Controller
public function store()
{
$input = Input::only('name','email','password');
$user = new User;
$user->name = $input['name'];
$user->email = $input['email'];
$user->password = Hash::make($input['password']);
$user->save();
}
And Route is just
Route::resource('users','UsersController');
Your input fields are all missing a name attribute! For example
<input type="text" class="form-control" id="name" name="name" value="a">
<!-- ^^^^^^^^^^^ -->
You should put name attributes on the input fields, because html forms communicate with php with name attribute.
Example:
<input........... name="etc">
and in controller use the name you have given an input as a key :
$user->name = $input['etc'];
<input type="text" class="form-control" id="name" name="name" value="a">