Update user on the same page laravel 5 - php

I am new to the framework and I have a question.
I made a login authentication to access and when I go to my profile page I can view my data and change all on the same page.
I need to go get my ID to be able to do the update or not needed?
What do I need to do?
The way I'm doing okay? I only need to create a route::post?
my profile page:
#if(Session::has('message'))
<div class="alert alert-danger">
<h5>{{ Session::get('message') }}</h5>
</div>
#endif
{!! Form::open(array('url' => 'backend/perfil', 'name' => 'updateProfile', 'role' => 'form'))!!}
<div class="row" style="margin-bottom: 20px;">
<div class="col-md-3 col-lg-3"></div>
<div class="col-md-2 col-lg-2">
{!! Form::label('name', 'Utilizador', ['class' => 'label_perfil']) !!}
</div>
<div class="col-md-5 col-lg-5">
{!! Form::text('name', null, ['class' => 'form-control input-md', 'placeholder' => 'Utilizador']) !!}
</div>
</div>
<div class="row" style="margin-bottom: 20px;">
<div class="col-md-3 col-lg-3"></div>
<div class="col-md-2 col-lg-2">
{!! Form::label('nascimento', 'Data de nascimento', ['class' => 'label_perfil']) !!}
</div>
<div class="col-md-5 col-lg-5">
{!! Form::date('nascimento', null, ['class' => 'form-control input-md']) !!}
{{ $errors->first('nascimento', '<span class=error>:message</span>') }}
</div>
</div>
<div class="row" style="margin-bottom: 20px;">
<div class="col-md-3 col-lg-3"></div>
<div class="col-md-2 col-lg-2">
{!! Form::label('sexo', 'Sexo', ['class' => 'label_perfil']) !!}
</div>
<div class="col-md-5 col-lg-5">
{!! Form::select('sexo', ['Masculino', 'Feminino'], null, ['class' => 'form-control input-md']) !!}
</div>
</div>
<div class="row" style="margin-bottom: 20px;">
<div class="col-md-3 col-lg-3"></div>
<div class="col-md-2 col-lg-2">
{!! Form::label('email', 'Email', ['class' => 'label_perfil']) !!}
</div>
<div class="col-md-5 col-lg-5">
{!! Form::text('email', null, ['class' => 'form-control input-md', 'placeholder' => 'Email']) !!}
</div>
</div>
<div class="row" style="margin-bottom: 20px;">
<div class="col-md-3 col-lg-3"></div>
<div class="col-md-2 col-lg-2">
{!! Form::label('password', 'Password', ['class' => 'label_perfil']) !!}
</div>
<div class="col-md-5 col-lg-5">
{!! Form::password('password', ['class' => 'form-control input-md', 'placeholder' => 'Password']) !!}
</div>
</div>
<div class="row" style="margin-bottom: 20px;">
<div class="col-md-3 col-lg-3"></div>
<div class="col-md-2 col-lg-2">
{!! Form::label('rpassword', 'Confirmar password', ['class' => 'label_perfil']) !!}
</div>
<div class="col-md-5 col-lg-5">
{!! Form::password('rpassword', ['class' => 'form-control input-md', 'placeholder' => 'Confirmar password']) !!}
</div>
</div>
<div class="row" style="margin-bottom: 20px;">
<div class="col-md-3 col-lg-3"></div>
<div class="col-md-2 col-lg-2">
{!! Form::label('imagem', 'Imagem', ['class' => 'label_perfil']) !!}
</div>
<div class="col-md-5 col-lg-5">
{!! Form::file('imagem', ['class' => 'input-file']) !!}
</div>
</div>
<div class="row" style="margin-bottom: 20px; margin-top: 30px;">
<div class="col-md-3 col-lg-3"></div>
<div class="col-md-9 col-lg-9">
{!! Form::submit('Enviar', ['class' => 'btn btn-primary']) !!}
</div>
</div>
{!! Form::close() !!}
My controller:
public function perfil() {
return view('backend/perfil.index');
}
public function updateProfile() {
$profileData = Input::except('_token');
$validation = Validator::make($profileData, User::$profileData);
if ($validation->passes()) {
User::where('id', Input::get('id'))->update($profileData);
return view('backend/perfil.index')->with('message', 'Updated Succesfully');
} else {
return view('backend/perfil.index')->with('message', $validation->messages());
}
}
My route:
Route::get('backend/perfil','BackendControlador#perfil');
Route::post('backend/perfil', 'BackendControlador#updateProfile');
My app User:
public static $profileData = array(
'email' => 'required|email',
'name' => 'required',
);

Here is the Detailed one what you wanted to do.
Step 1 : Open the Form
{!! Form::open(array('url' => 'updateProfile', 'name' => 'updateProfile', 'role' => 'form'))!!}
Note : Your form method action is empty. You shall view your source to see it
Step 2 : Write a route
Route::post('updateProfile', 'homeController#updateProfile');
It will call the homeController's updateProfile function
Step 3 : Define the Controller, validate the input and make your action done via model
Here's the simple/sample function for you
public function updateProfile()
{
$profileData = Input::except('_token');
$validation = Validator::make($profileData, User::$profileData);
if ($validation->passes()) {
User::where('id', Input::get('id'))->update($profileData);
return view('profile')->with('message', 'Updated Succesfully');
} else {
return view('profile')->with('message', $validation->messages());
}
}
What it does is it will get all the inputs except _token and store it in $profileData, then it will make a validation that is defined inside $profileData inside the User Model
Here is the Validator, you shall modify it
public static $profileData = array(
'email' => 'required|email',
'name' => 'required',
);
Step 4 : Return the Result
If the validation is passed, then it will update in the table to where the user whose id is passed i.e., Input::get('id') , and we will return the page with return view('profile')->with('message', 'Updated Succesfully');
I consider your page name as profile.blade.php and you shall change it according to your blade,
If the validation is failed, then we will return the page with error messages
return view('profile')->with('message', $validation->messages());
You should have this in your blade to display your error messages
#if(Session::has('message'))
<div class="alert alert-danger">
<h5>{{ Session::get('message') }}</h5>
</div>
#endif
Note :
If you don't want to refresh the page, then you shall just do an Ajax call to pass the variables and show/hide the results that is return by the Controller
Hope this helps you

Related

How to get saved value from dropdown in edit page laravel?

inside EmployeeController in the edit function, i have this code
public function edit($id)
{
$employees = Employee::find($id);
$departmentlists = Department::pluck('id', 'name');
return view('employees.edit', compact('employees', 'departmentlists'));
}
and inside edit.blade.php to display the dropdown i have this code
{!! Form::open(['action' => ['EmployeeController#update', $employees->id], 'method' => 'POST', 'autocomplete' => 'off', 'class' => 'form-horizontal', 'enctype' => 'application/x-www-form-urlencoded']) !!}
<div class="card">
<div class="card-header card-header-primary">
<h4 {{ Form::label('', 'Change Employee Data', ['class' => 'card-title']) }}
</h4>
<p class="card-category"></p>
</div>
<div class="card-body">
<div class="row">
<div class="col-md-12 text-right">
<a href="{{ route('employees.index') }}" class="btn btn-sm btn-primary" style="font-size:12px">
<i class="material-icons">keyboard_backspace</i>
{{ __('kembali') }}
</a>
</div>
</div>
<div class="row">
{{ Form::label('Name', '', ['class' => 'col-sm-2 col-form-label']) }}
<div class="form-group col-sm-7">
{{Form::text('name', $employees->name, ['class' => 'form-control', 'placeholder' => 'Name', 'required'])}}
<p style="color: red;">#error('name') {{ $message }} #enderror</p>
</div>
</div>
<div class="row">
{{ Form::label('Department', '', ['class' => 'col-sm-2 col-form-label']) }}
<div class="col-md-7">
<div class="form=group">
#foreach($departmentlists as $dl)
<option value="{{ $dl->id }}" #if($dl->id==$employees->department_id) selected='selected' #endif >{{ $employees->name }}</option>
#endforeach
<p style="color: red;">#error('id') {{ $message }} #enderror</p>
</div>
</div>
</div>
<div class="row">
{{ Form::label('Keterangan', '', ['class' => 'col-sm-2 col-form-label']) }}
<div class="form-group col-sm-7">
{{ Form::textarea('information', $employees->information, ['class' => 'form-control', 'placeholder' => 'Keterangan', 'rows' => '6', 'cols' => '50']) }}
</div>
</div>
</div>
<div class="card-footer ml-auto mr-auto">
{{ Form::hidden('_method','PUT') }}
{{ Form::submit('Ubah', ['class' => 'btn btn-primary']) }}
</div>
</div>
{!! Form::close() !!}
This is the employees table
and this is departments table
Now, the goal is i want the dropdown on edit page to display department name of the employee belongs to, while the dropdown still have all of the department name.
so i change can it, but when i run this code it gives me this error.
Trying to get property 'id' of non-object (View:
C:\xampp\htdocs\ims-it-laravel7\resources\views\employees\edit.blade.php)
i have read other threads here but those code still doesn't solve the problem
$departmentlists = Department::pluck('id', 'name');
Later You use
#foreach($departmentlists as $dl) and $dl->id
$dl is NOT an object, it is an array because of the pluck() function.
More precisely it looks like this
[
"abc" => 1
"xyz" => 2
"foo" => 3
]
Note: To see it Yourself try using dd($departmentlists) or dump($departmentlists)
Please see Laravel Eloquent Pluck
In this case You might want to use Department::select(['id', 'name'])->get() as it will return collection of objects with specified properties.

how make modal edit with jquery in laravel?

does every use of capital, have to use a validator in the store controller? and if you don't use a validator, what's the problem?
Index.blade.php
<td>
<a href="" class="edit_real" data-toggle="modal" data-target="#edit_real-{{$spent_time->plan_id}}">
{{$spent_time->plan->user_story}}
</a>
#include('reals._form')
</td>
_form.blade.php (modal)
<div class="modal fade" id="edit_real-{{$spent_time->plan_id}}" role="dialog" >
<div class="modal-dialog modal-sm-8">
<div class="modal-content">
<div class="nav-tabs-custom">
<ul class="nav nav-tabs pull-left">
<li class="">Plan</li>
<li class="active">Real</li>
</ul>
<div class="tab-content">
<div class="chart tab-pane active" id="revenue-chart">
{!! Form::open([$spent_time, 'url' => route('real.update', $spent_time->id), 'method' => 'POST', 'role'=>'form']) !!}
{{ csrf_field() }} {{ method_field('PUT') }}
<div class="box-body">
<div class="form-group">
{!! Form::label('user_story','Today Plan *', ['class' => 'control-label', 'name'=>'user_story']) !!}</label>
{!! Form::text('user_story', old('plan_id', is_null($spent_time->plan->user_story) ? null : $spent_time->plan->user_story), ['class'=>'form-control', 'readonly' => 'true']) !!}
</div>
<div class="form-group">
{!! Form::label('daily_spent_time','Spent Time *', ['class' => 'control-label', 'name'=>'daily_spent_time']) !!}</label>
{!! Form::text('daily_spent_time', old('daily_spent_time', $spent_time->daily_spent_time ?: null), ['class'=>'form-control', 'id'=>'daily_spent_time']) !!}
</div>
<div class="form-group">
{!! Form::label('daily_percentage','% Done *', ['class' => 'control-label', 'name' => 'daily_percentage']) !!}</label>
{!! Form::text('daily_percentage', old('daily_percentage', $spent_time->daily_percentage ?: null), ['class'=>'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('reason','Reason', ['class' => 'control-label', 'name'=>'reason']) !!}</label>
{!! Form::textarea('reason', old('reason', $spent_time->reason ?: null), ['class'=>'form-control']) !!}
</div>
<div class="form-group">
{!! Form::submit('Save', ['class' => 'btn btn-block btn-primary btn-flat']) !!}
</div>
</div>
</div>
</div>
</div>
</div>
<script>
// jquery
$('.edit_real').on('click', function (event) {
event.preventDefault();
$('#edit_real').modal();
});
</script>
this is the resulting display
the problem faced is that it cannot save data after editing. what should be repaired?
_form.blade.php (Modal)
<div class="form-group">
{!! Form::submit('Save', ['class' => 'btn btn-block btn-primary btn-flat', 'type'=>'submit']) !!}
</div>

Laravel 5.1 issues with generating PDF & {!! Form::text or {!! Form::textarea

I started to learn Laravel (nice framework), and being more and more familiar with it. But I arrive at a point where I don't understand why and how..
I generate a PDF from one of my view. The view is just composed by 3 {!! Form::text , which are filled by Varchar (length:2000) coming from my database.
I well generate the PDF but i can't understand why the text inside goes totally out of the the {!! Form::text in the .pdf-file.
I can't understand why the text stand inside the {!! Form::text for the first lines, but at the last one, the text will go out of the box and keep being writing until it touch the right margin of the pdf, and so diseapper..
I try to play around with {!! Form::text or {!! Form::textarea: same results..
I try to play around with " 'rows' => '15', 'cols' => '100'," parameters: same results...
Does someone might have an idea on why the text doesn't want to stay inside its {!! Form::textarea for description/sentiment and position forms?
My view:
#extends('template')
#section('contenu')
<div class="container">
<div class="jumbotron">
<h2> PTS | <em><strong> Weekly Comments</strong></h2>
<h3><strong>week: {{$week_number}}</strong></h3>
<br>
</div>
#foreach($comments as $comment)
<div class="row">
<div class="panel panel-primary">
<div class="panel-heading" style="text-align:center">
<h3{!! Form::textarea('desk_name', $comment->desk_name, array( 'class'=>'form-control','type' => 'text', 'rows'
=> '5', 'cols' => '5')) !!}</h3>
</div>
</div>
</div>
<br/>
<div class="row">
<div class="col-md-4">
<h3> P&L Weekly | </h3>
{!! Form::textarea('pnl_wtd', $comment->pnl_wtd, array( 'class'=>'form-control','type' => 'text', 'rows' => '5',
'cols' => '5')) !!}
</div>
<div class="col-md-4">
<h3> P&L MTD | </h3>
{!! Form::textarea('pnl_mtd', $comment->pnl_mtd, array('class'=>'form-control','type' => 'text', 'rows' => '5',
'cols' => '5')) !!}
</div>
<div class="col-md-4">
<h3> P&L YTD | </h3>
{!! Form::textarea('pnl_ytd', $comment->pnl_ytd, array( 'class'=>'form-control','type' => 'text', 'rows' => '5',
'cols' => '5')) !!}
</div>
</div>
<br>
<br>
<div class="row">
<div class="panel panel-warning">
<div class="panel-heading" style="text-align:center">
<h3>Past Week Summary</h3>
</div>
<div class="panel-body">
<div class="col-lg-8">
{!! Form::textarea('description', $comment->description, ['class' => 'textarea']) !!}
</div>
</div>
</div>
</div>
<div class="row">
<div class="panel panel-warning">
<div class="panel-heading" style="text-align:center">
<h3>Sentiment</h3>
</div>
<div class="panel-body">
<div class="col-lg-8">
{!! Form::textarea('sentiment', $comment->sentiment, ['class' => 'form-control', 'type' => 'text', 'rows' =>
'100000', 'cols' => '100000']) !!}
</div>
</div>
</div>
</div>
<div class="row">
<div class="panel panel-warning">
<div class="panel-heading" style="text-align:center">
<h3>Positions</h3>
</div>
<br>
</div>
</div>
<div class="container" id="posi">
{!! Form::textarea('position', $comment->position, ['class' => 'form-control', 'style'=>'resize: none']) !!}
</div>
#endforeach
#stop
The function from my controller:
public function pdfWeekly( $week_number ) {
$picuser = Auth::user();
$comments = Comment::where( 'week_number', '=', $week_number )->get();
$flag = 'pdf';
$pdf = PDF::loadView( 'tr.wc.emailPdf', compact(
'picuser',
'flag',
'week_number',
'comments'
) );
$name = "Principale Trading- Week #" . $week_number . ".pdf";
return $pdf->download( $name );
}
Best Regards.
The pdf use native html layouts. So your framework classes and expressions wont work here.
Try making a divv with width 710px and put you data in that div, it won't flow out.
I have a solution for this it is replace input or textarea to a tag like a textarea-to-text before save. I do:
var $html = $('html').clone();
$($html).find('textarea').replaceWith(function () {
$element = $("<textarea-to-text>").text($(this).val());`
$.each(this.attributes, function (i, attribute) {
$element.attr(attribute.name, attribute.value);
});
return $element;
});`

Insert Cart::content() into multiple Row From View Using Eloquent Laravel 5

How can I insert Multiple Row of Cart:: content() in Laravel 5.
I'm using Crinsane/LaravelShoppingcart for my cart, however, when you click on proceed to payment, I want the user to fill Customer details like (Terminal ID, sale date, and customer name. But I'm having issue with inserting Cart::(Content) into my database (I dont want to insert instance. I like to break the cart down to my database column. example, if someone pick like 2-5 items, I want it to be inserted to my db, with each item in each row. I've break the Cart::content down in my view, but I need to be able to use Laravel to insert multiple row based on the number of Items selected.
PLEASE NOTE: IF I ONLY ADD ONLY ONE ITEM TO CART, I'M ABLE TO INSERT TO DATABASE, IT'S ONLY WHEN THE ITEM IN CART IS MORE THAN ONE THAT I HAVE ISSUE WITH.
Below is my proceed.blade.php
<div class="panel-heading">Customer Detail</div>
<div class="panel-body">
#if (sizeof(Cart::content()) > 0)
{!! Form::open(['method'=>'POST', 'action'=> 'SalesController#store','files'=>true]) !!}
{!! Form::text('counter', $counter=Cart::content()->groupBy('id')->count(), ['class'=>'form-control'])!!}
#foreach (Cart::content() as $item)
<div class="form-group">
{!! Form::label('product_name', 'Product Name:') !!}
{!! Form::text('product_name', $item->name, ['class'=>'form-control'])!!} </div>
<div class="form-group">
{!! Form::label('quantity', 'Quantity:') !!}
{!! Form::text('quantity', $item->qty, ['class'=>'form-control'])!!}
</div>
<div class="form-group">
{!! Form::label('unit_price', 'Unit Price:') !!}
{!! Form::text('unit_price', $item->price, ['class'=>'form-control'])!!}
</div>
<div class="form-group">
{!! Form::label('rowId', 'Row ID:') !!}
{!! Form::text('rowId', $item->rowId, ['class'=>'form-control'])!!}
</div>
<div class="form-group">
{!! Form::label('tax', 'Tax:') !!}
{!! Form::text('tax', $item->tax, ['class'=>'form-control'])!!}
</div>
<div class="form-group">
{!! Form::label('total_price', 'Sub Total:') !!}
{!! Form::text('total_price', $item->subtotal, ['class'=>'form-control'])!!}
</div>
#endforeach
#endif
<div class="form-group">
{!! Form::label('terminal_id', 'Terminal ID:') !!}
{!! Form::text('terminal_id', null, ['class'=>'form-control'])!!}
</div>
<div class="form-group">
{!! Form::label('customer_name', 'Customer Name:') !!}
{!! Form::text('customer_name', null, ['class'=>'form-control'])!!}
</div>
<div class="form-group">
{!! Form::label('sale_date', 'Sale Date:') !!}
{!! Form::text('sale_date', null, ['class'=>'form-control'])!!}
</div>
<div class="form-group">
{!! Form::submit('Check Out', ['class'=>'btn btn-primary']) !!}
</div>
{!! Form::close() !!}
`
MY CONTROLLER
$counter= $request['counter'];
for ($i = 0; $i < count($counter); $i++) {
Sale::create([
'terminal_id' => $request['terminal_id'],
'customer_name' => $request['customer_name'],
'unit_price' => $request['unit_price'],
'total_price' => $request['total_price'],
'tax' => $request['tax'],
'quantity' => $request['quantity'],
'product_name' => $request['product_name'],
'sale_date' => $request['sale_date'],
'rowId' => $request['rowId']
]);
}
return redirect('shop');
}
First your fields are not arrays so with each #foreach in your view, the old value overrides.
Make your inputs to Array inputs by changing your view this way:
<div class="panel-heading">Customer Detail</div>
<div class="panel-body">
#if (sizeof(Cart::content()) > 0)
{!! Form::open(['method'=>'POST', 'action'=> 'SalesController#store','files'=>true]) !!}
{!! Form::text('counter', $counter=Cart::content()->groupBy('id')->count(), ['class'=>'form-control'])!!}
<?php $idx = 0; ?>
#foreach (Cart::content() as $item)
<div class="form-group">
{!! Form::label("product_name[$idx]", 'Product Name:') !!}
{!! Form::text("product_name[$idx]", $item->name, ['class'=>'form-control'])!!}
</div>
<div class="form-group">
{!! Form::label("quantity[$idx]", 'Quantity:') !!}
{!! Form::text("quantity[$idx]", $item->qty, ['class'=>'form-control'])!!}
</div>
<div class="form-group">
{!! Form::label("unit_price[idx]", 'Unit Price:') !!}
{!! Form::text("unit_price[idx]", $item->price, ['class'=>'form-control'])!!}
</div>
<div class="form-group">
{!! Form::label("rowId[$idx]", 'Row ID:') !!}
{!! Form::text("rowId[$idx]", $item->rowId, ['class'=>'form-control'])!!}
</div>
<div class="form-group">
{!! Form::label("tax[$idx]", 'Tax:') !!}
{!! Form::text("tax[$idx]", $item->tax, ['class'=>'form-control'])!!}
</div>
<div class="form-group">
{!! Form::label("total_price[$idx]", 'Sub Total:') !!}
{!! Form::text("total_price[$idx]", $item->subtotal, ['class'=>'form-control'])!!}
</div>
<?php $idx++; ?>
#endforeach
#endif
<div class="form-group">
{!! Form::label('terminal_id', 'Terminal ID:') !!}
{!! Form::text('terminal_id', null, ['class'=>'form-control'])!!}
</div>
<div class="form-group">
{!! Form::label('customer_name', 'Customer Name:') !!}
{!! Form::text('customer_name', null, ['class'=>'form-control'])!!}
</div>
<div class="form-group">
{!! Form::label('sale_date', 'Sale Date:') !!}
{!! Form::text('sale_date', null, ['class'=>'form-control'])!!}
</div>
<div class="form-group">
{!! Form::submit('Check Out', ['class'=>'btn btn-primary']) !!}
</div>
{!! Form::close() !!}
I suggest you also putting your for loop in a transaction in order to improve it's safety.
Like this:
public function store(SalesCreateRequest $request) {
$counter = Input::get('counter');
\DB::transaction(function() use ($counter){
for ($i=0; $i < $counter; $i++){
Sale::create([
'terminal_id' => Input::get("terminal_id")[$i],
'customer_name'=> Input::get("customer_name")[$i],
'unit_price'=> Input::get("unit_price")[$i],
'total_price'=> Input::get("total_price")[$i],
'tax'=> Input::get("tax")[$i],
'quantity'=> Input::get("quantity")[$i],
'product_name'=> Input::get("product_name")[$i],
'sale_date'=> Input::get("sale_date")[$i],
'rowId'=> Input::get("rowId")[$i]
]);
}
});
return "working";
}
Note that you could simply add a [] suffix instead of [$idx] in your input names to make your inputs arrays, but usually indexing your inputs explicitly is safer.
Edit the $idx key from Cart::content() was returning a weird number, that was why simple numerical numbers threw Out of range exception.
Change your view code as I did above, I hope fixing it this way.
Hope it helps
Just modify your controller
$counter = $request['counter'];
\DB::transaction(function() use ($counter, $request) {
for ($i = 0; $i < count($counter); $i++) {
Sale::create([
'terminal_id' => $request["terminal_id"],
'customer_name' => $request["customer_name"],
'unit_price' => $request["unit_price"][$i],
'total_price' => $request["total_price"][$i],
'tax' => $request["tax"][$i],
'quantity' => $request["quantity"][$i],
'product_name' => $request["product_name"][$i],
'sale_date' => $request["sale_date"],
'rowId' => $request["rowId"][$i]
]);
}
});
NOTE
Not all input fields are array (terminal_id, sale_date...)

Dynamically created input values are not being posted to Controller in Laravel

I am creating some dynamic fields via jQuery in my existing form that user is filling, but after submission of that form I am unable to get those fields in my controller. All other fields are present except those which I am creating dynamically. This is my code for inserting the fields:
//load the rosters levels using ajax
$.ajax({
'url': '/rosters/load-levels',
'data': {'id': rosterId, 'name': rosterName},
'method': 'post',
dataType: 'json',
success: function (data) {
$('<div class="row" id="show_rosters_field_row" style="margin-top: 20px">'+
'<div class="col-md-3">'+
'<div class="row">'+
'<div class="col-md-12">'+
"<label for='position' class = 'control-label'>Position</label>"+
"<input type='text' name='position[]' class = 'form-control' required>"+
'</div>'+
'</div>'+
'</div>'+
'<div class="col-md-3">'+
'<div class="row">'+
'<div class="col-md-12">'+
"<label for='jersey' class = 'control-label'>Jersey</label>"+
"<input type='text' name='jersey[]' class = 'form-control' required>"+
'</div>'+
'</div>'+
'</div>'+
'<div class="col-md-3">'+
'<div class="row">'+
'<div class="col-md-12">'+
"<label for='ros_photo' class = 'control-label'>Photo</label>"+
"<input type='file' name='ros_photo[]' class = 'form-control'>"+
'</div>'+
'</div>'+
'</div>'+
'<div class="col-md-3">'+
'<div class="row">'+
'<div class="col-md-12">'+
"<label for='levels' class = 'control-label'>Roster Levels</label>"+
"<select id='"+rosterNameForId+"' class='form-control' name='ros_level[]' required></select>"+
'</div>'+
'</div>'+
'</div>'+
'</div>'+
'<input type="hidden" value="'+rosterId+'" class="roster_id_js" name="_roster_id[]">'
).insertAfter($('#add-rosters-before'))
$.each(data, function (index, item) {
$("#" + rosterNameForId).append('<option value="'+item.id+'" class="form-control">'+item.name+'</option>');
})
},
error: function (error) {
console.log(error);
}
})
Base Form code before appending any fields via js
<div class="container-fluid" id="dynamics-form-outer">
<h2 style="text-align: center">Add Student</h2>
#include('partials.error-messages.success')
#include('partials.error-messages.error')
{!! Form::open(['url' => 'students/', 'files' =>true, 'id' => '']) !!}
<div class="row">
<div class="col-md-6">
{!! Form::label('title', 'Name:', ['class' => 'control-label']) !!}
{!! Form::text('name', null, ['class' => 'fn form-control', 'required' => 'true']) !!}
</div>
<div class="col-md-6">
{!! Form::label('academic_year', 'Academic Year:', ['class' => 'control-label']) !!}
{!! Form::select('academic_year',
['Freshman' => 'Freshman', 'Sohphomore' => 'Sohphomore',
'Junior' => 'Junior', 'Senior' => 'Senior'], 'Please Select'
,['class' => 'form-control']) !!}
</div>
</div>
<div class="row">
<div class="col-md-6">
{!! Form::label('title', 'Weight(pounds):', ['class' => 'control-label']) !!}
{!! Form::selectRange('weight', 80, 220, 80, ['class' => 'form-control']) !!}
</div>
<div class="col-md-6">
<div class="row">
<div class="col-md-6">
{!! Form::label('title', 'Height in Feet:', ['class' => 'control-label']) !!}
{!! Form::selectRange('height_feet', 4, 7, 4, ['class' => 'form-control']) !!}
</div>
<div class="col-md-6">
{!! Form::label('title', 'Height in Inches:', ['class' => 'control-label']) !!}
{!! Form::selectRange('height_inches', 0, 12, 0, ['class' => 'form-control']) !!}
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
{!! Form::label('pro_free', 'Pro/Free:', ['class' => 'control-label']) !!}
{!! Form::select('pro_free', ['' => 'Please Select', '0' => 'Free', '1' => 'Pro'],'please select',
['class' => 'fn form-control', 'id'=>'pro_free_', 'onchange' => 'return pro()', 'required' => true]) !!}
</div>
<div class="col-md-6">
</div>
</div>
<div class="row">
<div class="col-md-6">
{!! Form::label('pro_head_photo', 'Pro Head Photo:', ['class' => 'control-label hide-pro']) !!}
{!! Form::file('pro_head_photo', ['class' => 'fn form-control hide-pro']) !!}
</div>
<div class="col-md-6">
{!! Form::label('pro_cover_photo', 'Pro Cover Photo:', ['class' => 'control-label hide-pro']) !!}
{!! Form::file('pro_cover_photo', ['class' => 'fn form-control hide-pro']) !!}
</div>
</div>
{{--show custom fields--}}
<div class="row" style="margin: 20px 20px 20px 0px">
<div class="col-md-12">
<b>{{$school->name}} Custom Fields: </b>
<button style="" type="button" id="add-field" class="btn btn-default">
Add Fields?</button>
</div>
</div>
<div class="row" id="dynamic-fields-row">
{{--will append the data on button click--}}
</div>
</div>{{--container fluid closed--}}
<div class="container-fluid">
#if($customFields)
#foreach($customFields as $customField)
<div class="row" id="" style="">
<div class="col-md-6" id="">
<div class="row" style="margin-top: 10px">
<div class="col-md-6">
<input value="{{$customField->custom_label}}" readonly type="text" name="custom-field-name[]" class="form-control col-md-3">
</div>
<div class="col-md-6">
<input type="text" name="custom-field-value[]" class="form-control col-md-3" placeholder="Value">
</div>
</div>
</div>
</div>
#endforeach
#endif
{{--add rosters to students--}}
<div class="row" id="add-rosters-before">
<div class="col-md-12">
<h3 style="text-align: center">Add to Sports</h3>
<div class="row">
<div class="col-md-4 col-md-offset-3">
{!! Form::select('rosters', $rosters, null, ['class' => 'form-control',
'id' => 'rosters_id']) !!}
</div>
<div class="col-md-4">
<button class="btn btn-default" id="add-rosters-btn">Add Roster?</button>
</div>
</div>
</div>
</div>
<div class="row" style="margin: 0 auto; width: 300px; padding: 10px">
<div class="" style="margin-top: 20px; margin-left: 10px !important; float: left;">
{!! Form::submit('Create Student', ['class' => 'btn btn-primary']) !!}
</div>
</div>
{!! Form::close() !!}
</div>
looks like it was an issue in the html structure, some tags were not being closed. Correcting that fixed my issue.

Categories