I have fleshed out a Laravel project but wanting to do something a little different, I am using Bootstrap so the standard nav and modal for the popout.
I am wanting to show the modal with the registration or login form inside, but as you can appreciate the way it is currently built, once you hit the login or register link it just renders the page view.
So I have my views/layouts/navigation.blade.php
<div class="container navigation">
<nav class="navbar navbar-default navbar-top">
<li class="navbar-right">Home</li>
<div class="container">
#if(Auth::check())
<li>Sign out</li>
<li>Change password</li>
#else
<li>Login</li>
<li><button type="button" class="btn btn-default navbar-btn data-toggle="modal" data-target="#myModal"">Sign Up</button></li>
#endif
</div>
</nav>
</div>
And seperate to this I have my views/account/create.blade.php & views/account/signin.php
#extends('layout.main')
#section('content')
<form action="{{ URL::route('account-create-post') }}" method="post">
<div class="field">
Email: <input type="text" name="email"{{ (Input::old('email')) ? ' value="' . e(Input::old('email')) . '"' : '' }}>
#if($errors->has('email'))
{{ $errors->first('email') }}
#endif
</div>
<div class="field">
Username: <input type="text" name="username"{{ (Input::old('email')) ? ' value="' . e(Input::old('username')) . '"' : '' }}>
#if($errors->has('username'))
{{ $errors->first('username') }}
#endif
</div>
<div class="field">
Password: <input type="password" name="password">
#if($errors->has('password'))
{{ $errors->first('password') }}
#endif
</div>
<div class="field">
Password Again: <input type="password" name="password_again">
#if($errors->has('password_again'))
{{ $errors->first('password_again') }}
#endif
</div>
<input type="submit" value="Create Account">
{{ Form::token() }}
</form>
#stop
Really I wanting the button in the nav to fire up the modal and show the forms inside? Amy ideas on how to approach this?
You'll basically be using Javascript on the client to display the form and process the request to the server and the server's response. I would:
Pick a CSS/Javascript framework that will display a modal form for you
Put your normal form generation inside the dialog it shows
Have a Javascript handler on the submit button of the modal dialog that makes an AJAX post to a new RESTful HTTP endpoint in Laravel that calls the same logic your standard signup form uses, but sends back a response your AJAX code will understand (e.g. either successful or failed, with an error message).
I hope i got the question right. The Key to achieve what you want should be a concept called nested views, which is very well explained on this coderwall. Also, check out the laravel docs on views (passage Passing A Sub-View To A View).
You would have to create a view for your login-form an nest it in the login modal as well as in the standard login-view (if you have one). Hope this helps.
Related
I have a problem with my Laravel and probably routes but I'm not sure.
So, there is a contact form in modal window. When I click on Send button I've got page not found error.
What I have in the web.php is
Route::post('/apply_now','HomeController#apply_now')->name('apply_now');
In the HomeController.php
public function apply_now(Request $request)
{
... form fields data
return Redirect::to('/')->with('message', 'Sent');
}
And the form
{{Form::open(array('route'=>'apply_now','files' => true,'method'=>'post'))}}
...
form field
{{Form::close()}
The error
Not Found
The requested URL /apply_now was not found on this server.
I don't see anything wrong with the routes but yet can't find the problem.
UPDATE:
| | POST | apply_now | apply_now | App\Http\Controllers\HomeController#apply_now
UPDATE 2. The modal
<!-- Apply Modal -->
<div class="modal fade" id="apply" tabindex="-1" role="dialog" aria-labelledby="applyModalLable">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title text-center" id="applyModalLable">Apply Now</h4>
</div>
<div class="modal-body">
<form method="POST" action="https://example.com/apply_now" accept-charset="UTF-8" enctype="multipart/form-data">
<input name="_token" type="hidden" value="OyEdnHIWRgbZmPo0joodNmWraDSuuACIrwqup044">
<div class="form-group ">
<input type="text" name="your_name" class="form-control" placeholder="*Your Name" value="" >
</div>
<div class="form-group ">
<label>*Country</label>
<input type="text" name="country" class="form-control" placeholder="Your Country" >
</div>
<div class="form-group ">
<input type="text" name="contact_email" class="form-control" placeholder="*Contact Email" >
</div>
<div class="form-group ">
<input type="text" name="contact_phone" class="form-control" placeholder="*Contact Phone">
</div>
<div class="form-group text-center">
<button type="submit" class="btn btn-custom btn-sm btn-block">Submit</button>
</div>
</form>
</div>
</div>
</div>
</div>
make routes like this:
Route::match(['get', 'post'],'/apply_now', 'HomeController#apply_now');
Looks like there is no error in the code, can you clear the cache;
php artisan route:cache
enter image description here
Did you see the area in the picture?
Try Adding
{{ csrf_field() }}
This will add the CRSF Token field to your form
eg. <input type="hidden" name="_token" value="SomeRandomString">
which is required by laravel ,CSRF is enabled by default on all Routes to check if the post request is secure , you can also disable it from VerifyCsrfToken.php which is middleware located at
app\Http\Middleware
To Disable the CRSF for your route
update
protected $except = [
//
'apply_now'
];
Disabling this is not a good practice, If you want your application secure
Add
{{ csrf_field() }}
In your form for.eg.
{{ Form::open(array('route'=>'apply_now','files' => true,'method'=>'post')) }}
...
form field
{{ csrf_field() }}
{{ Form::close() }}
Now once you submit the form laravel will check if crsf token is sent with the form and let your request proceed further
Try with this,
Route::get('/', 'HomeController#index')->name('home');
In your controller
return redirect()->route('home')->with('message', 'Sent');
Hope this helps :)
Run this command and try again
php artisan optimize:clear
or
remove all files from the
/bootstrap/cache
/storage/framework/cache/data
/storage/framework/sessions
/storage/framework/views
and make sure you have defined both urls into web.php file something like this:
Route::post('/','HomeController#index');
Route::post('apply_now','HomeController#apply_now')->name('apply_now');
and make sure your server has turned on mod rewrite. So Laravel can handle .htaccess rules.
When I select a class from in my view and click on Genrate, I try to retrieve the value of the selected class but I am not able to get the value of the class selected.
When I return $condition, it returns empty. In the url after submitting, it shows like http://localhost:8000/generate/timetable?class=
Why is this happening?
<div class="row">
<div class="col-xl-4 col-lg-12 col-md-12 mb-1">
<fieldset class="form-group">
<label for="squareText">Type</label>
{{ Form::select('class',$classes,$selectedClass,['class'=>'form-control','required'=>'true'])}}
<br>
<button class="btn btn-primary pull-left square" type="submit"><i class="glyphicon glyphicon-th"></i> Generate</button>
</fieldset>
</div>
</div>
Controller
$condition = Input::get('class');
if (!isset($condition['class']))
$condition['class'] = 0;
$courses = $course->where('class',$condition)->get()->toArray();
return $condition;
Your button is inside a link:
<a href="/generate/timetable?class={{ request('class') }}">
<button class="btn btn-primary pull-left square" type="submit"> ... </button>
</a>
Clicking it is actually clicking the <a href> link, not clicking the button and submitting the form. So instead of submitting the form, you are simply browsing to the URL the the link points to.
It isn't clear from your question what the link is there for, but if clicking the button is supposed to submit the form, you probably want to put your form elements inside an actual <form>.
It looks like you're using Laravel Collective ({{ Form::select('class .... looks like that), so see those docs on how to open a form:
{!! Form::open(['url' => '/generate/timetable?class=' . request('class')]) !!}
{{ Form::select('class' .... }}
<button class="btn btn-primary pull-left square" type="submit"> ... </button>
{!! Form::close() !!}
You'll probalby also need to add a CSRF token, it is also described in the Laravel Collective docs, as well as in the Laravel docs.
I'm trying to resize a form box using .col-md-12. It works fine if I keep the code inside the span tag as it is, but if I take it off (and I want to, because I need to remove that button) it stops working. In this scenario the form box will maintain some kind of default size, no matter which value is inserted after -md.
Could anyone give some help? If it matters, this HTML file is part of the viewer of a project using laravel framework.
<div class="box-body">
<div class="col-md-12">
<div class="form-group">
<label for="name">{{ 'name' }}</label>
<div class="input-group">
<input class="form-control" type="text" name="name" value="{{ $name }}">
<span class="input-group-btn">
<a class="btn btn-warning" href="{{ url('path', $id) }}" title="{{ 'edit' }}"><i class="fa fa-pencil"></i></a>
</span>
</div>
</div>
</div>
</div>
Provided that I understood your question right, just add the btn class to the span tag and remove the a tag.
<span class="input-group-btn btn">
<!-- removed button -->
</span>
I am developing project management application using Laravel 5.2. in My application side bar menus as sidebar.blade.php witch located in views\layouts\partials\sidebar.blade.php
<li>Edit Account</li>
<li>Projects</li>
<li>Collaborators</li>
<li>Todos</li>
when I click project link in the sidebar pages view existing pages. and now I need add some collaborators to each project when click collaborators link in the sidebar. my collaborators form in view/collaborators/form
<div class="col-md-4" style="border:1px solid #ccc;margin-left:15px;padding:10px;">
<h4 class="page-header">
Collaborators
</h4>
<form class="form-vertical" role="form" method="post" action="">
<div class="form-group{{ $errors->has('name') ? ' has-error' : '' }}">
<label> Add New </label>
<input type="text" name="task_name" class="form-control" id="name" value="{{ old('task_name') ?: '' }}">
#if ($errors->has('task_name'))
<span class="help-block">{{ $errors->first('task_name') }}</span>
#endif
</div>
<div class="form-group">
<button type="submit" class="btn btn-info">Add User</button>
</div>
<input type="hidden" name="_token" value="{{ csrf_token() }}">
</form>
</div>
my problem is this i need consider when I am in project 10 and I click collaborator link and then I need following localhost url
localhost:8000/project/10/collaborators
My existing routes is this
Route::get('/collaborators', function(){
return view('collaborators.form');
})->name('collaborators.form');
but it is generated only localhost url as
http://localhost:8000/collaborators
how can I manages this?
Maybe I am missing something but are you trying to do this:
Route::get('/project/{project}/collaborators', function(){
return view('collaborators.form');
})->name('collaborators.form');
And use route('collaborators.form', $project)
I have a model Testcase in my database which has a field called "testcaseOrder" which I use to order my models in the view.
I render all Testcase models into a form and implemented some logic, so I can rearrange the order by using drag & drop and then update the models with the new order.
<form id="store" class="center" method="POST" action="{{url("testcase/updateOrder/$model_id")}}" enctype="multipart/form-data">
{{ csrf_field() }}
<ul id="sortable" class="connectedSortable form-group">
#foreach($AllTestcases as $testcase)
<li class="ui-state-default" name="testcases[]" id="{{ $testcase->id }}" value="{{ $testcase->testcaseOrder }}">{{ $testcase->name }}</li>
#endforeach
</ul>
<div class="form-group">
<button type="submit" id="save" class="btn btn-default">Speichern</button>
</div>
#include('partials.errors')
</form>
After submitting the form I try to access the values in my controller like this:
public function updateOrder($scenario_id)
{
dd(request('testcases'));
...
}
However, I get null back as result.
What am I doing wrong?
Notes:
I already checked if $model_id and $scenario_id are correct.
$testcase->testcaseOrder is of type integer
Change your list to this:
<li class="ui-state-default">
<input type="hidden" name="testcases[]" id="{{ $testcase->id }}" value="{{ $testcase->testcaseOrder }}" />
{{ $testcase->name }}
</li>