I'm using javascript to dynamically create a form that takes answers from a chat and adds it to a form. The form exists in a separate blade file register.blade.php
. I yielded the form in the home page (index.blade.php
) but the @section('registration-form')
yields to the page before the js is read. For that reason, the answers from the chat never get input into the form.
register.blade.php
holds the (custom) form @section('registration-form')
. From there I'd like to create a route::get('/index', 'CustomAuthController')
in routes/web.php
to store the forms data in my database. Any ideas on how to make this work?
Very new to Laravel. Using Laravel 5.4.
THE CODE:
layouts/app.blade.php
@include('includes.head')
<body>
@include('includes.navbar')
<div class="container">
@yield('content')
</div>
@include('includes.footer')
</body>
index.blade.php
@extends('layouts.app')
@section('content')
<main>
<section class="row" >
<!------ a bunch of content here ----------->
<!----- form yielded here -------->
@yield('registration-form')
<!--- form end ----->
<!------ more content -------->
</section>
</main>
@endsection
register.blade.php
@section('registration-form')
<div class="padding-32" id="signup-two">
<h4>Review and submit your information</h4>
<form method="POST" action="{{ route('signup') }}">
{{ csrf_field() }}
<div class="form-group" id="fname">
<label></label>
<input name="fname"/>
</div>
<div class="form-group" id="email">
<label></label>
<input name="email"/>
</div>
<div class="form-group" id="password">
<label></label>
<input name="password"/>
</div>
<div class="form-group" id="BMI">
<label></label>
<input name="BMI"/>
</div>
<div class="form-group" id="height">
<label></label>
<input name="height"/>
</div>
<div class="form-group" id="weight">
<label></label>
<input name="weight"/>
</div>
</form>
@endsection
I tried yielding @section(registration-form)
in app.blade.php
the form still did not load. I also couldn't figure out how to create a route and a controller for this. The code looked like this:
layouts/app.blade.php
@include('includes.head')
<body>
@include('includes.navbar')
<div class="container">
@yield('content')
@yield('registration-form')
</div>
@include('includes.footer')
</body>
</html>
routes/web.php
Route::get('/index', function () {
return view('registration-form', [
'fname' => 'fname',
'BMI' => 'BMI',
'height' => 'height',
'weight' => 'weight'
]);
});