MediumText and textArea in my form show.blade - php

I need your help because I am stuck... I should create a form with a text long.
In my function up(), I have this
$table->mediumText('resume');
In my page create.blade.php, the create works.
<fieldset class="form-group {{ $errors->has('resume') ? 'has-error' : '' }}">
<label for="form-group-input-1">Résumé</label>
<textarea name="resume" id="resume" class="form-control" required="required" value="{{ old('resume')}}"/></textarea>
{!! $errors->first('resume', '<span class="help-block">:message</span>') !!}
</fieldset>
However, I don't get the value (the text) on my page show.blade.php
<fieldset class="form-group">
<label for="form-group-input-1">Résumé</label>
<textarea name="resume" class="form-control" id="form-group-input-1" readonly="true" value="{{$livres->resume}}"/></textarea>
</fieldset>
If I don't use textarea but input type=text it works.
Do you have an idea please?

instead of this
<fieldset class="form-group">
<label for="form-group-input-1">Résumé</label>
<textarea name="resume" class="form-control" id="form-group-input-1" readonly="true"
value="{{$livres->resume}}"/></textarea>
</fieldset>
use this
<fieldset class="form-group">
<label for="form-group-input-1">Résumé</label>
<textarea name="resume" class="form-control" id="form-group-input-1" readonly="true"/>{{$livres->resume}}</textarea>
</fieldset>

Change your code like this (textarea does not get value):
<textarea name="resume" class="form-control" id="form-group-input-1" readonly="true"/>{{$livres->resume}}</textarea>

Related

How to use variable in value attribute of textarea in Laravel - Blade?

I've got the following blade file. I'm passing in a project object with a title and description and I want to populate the value attributes. The description variable works inside the p-tag, but not in the textarea-tag. The $title variable works fine also. Why doesn't it work in the textarea?
#extends('layout')
#section('content')
<h1 class="display-4">Edit Project</h1>
<p>{{ $project->description }}</p>
<form>
<div class="form-group">
<label for="title">Title</label>
<input type="text" class="form-control" name="title" placeholder="Title" value="{{ $project->title }}">
</div>
<div class="form-group">
<label for="description">Description</label>
<textarea type="text" class="form-control" name="description" value="{{ $project->description }}"></textarea>
</div>
<button type="submit" class="btn btn-primary">Update Project</button>
</form>
#endsection
There is no value attribute in textarea tag. Instead, put the value between open and close tag:
<textarea type="text" class="form-control" name="description">{{ $project->description }}</textarea>
See this link for more information.
It should be like
<textarea type="text" class="form-control" name="description" >{{ $project->description }}</textarea>

After submitting a form i get an error "Sorry, the page you are looking for could not be found."

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>

Issue populating textarea with db data

So, like the title said, i'm having an issue while i'm populating a text area that is being used on HTML form, because it is not getting any content in it.
this is the form with the php while.
<?php
while ($row = mysqli_fetch_array($query))
{ echo '
<form action="insert/insertReport.php" id="newReport" method="post">
<div class="form-group">
<label for="clientRep">Cliente</label>
<br>
<input type="text" name="client" class="form-control" id="client" value="'.$row['client'].'">
</div>
<div class="form-group">
<label for="titleRep">Título do Relatório</label>
<br>
<input type="text" name="title" class="form-control" id="title" value="'.$row['title'].'">
</div>
<div class="form-group">
<label for="namefat">Data</label>
<br>
<input type="text" name="date" class="form-control" id="date" value="'.$row['date'].'">
</div>
<div class="form-group">
<label for="localRep">Local</label>
<br>
<input type="text" name="local" class="form-control" id="local" value="'.$row['local'].'">
</div>
<div class="form-group">
<label for="reportRep">Relatório</label>
<br>
<textarea rows="12" name="report" class="form-control" id="report" form="newReport" value="'.$row['report'].'"></textarea>
</div>
<input type="hidden" name="id" class="form-control" id="id" value="'.$row['id'].'">';
}?>
And this is the php query.
$sql = 'SELECT * FROM reports'
Does anyone know what's wrong with it?
Text area does not accept a value attribute. You place the contents between the textarea tags:
<textarea rows="12" name="report" class="form-control" id="report" form="newReport">'.$row['report'].'</textarea>

TokenMismatchException in VerifyCsrfToken.php line 46 ocassionally showing

I already set the token in the form:
<form action="{{ route('user.store') }}" method="post">
<input type="hidden" name="_token" value="{!! csrf_token() !!}">
<legend>Agregar nuevo usuario.</legend>
<div class="form-group">
<label>Código empresa</label>
<input type="number" class="form-control input-sm" name="enterprise" id="enterprise">
</div>
<div class="form-group">
<label>Nombre</label>
<input type="text" class="form-control input-sm" name="name" id="name">
</div>
<div class="form-group">
<label>Email</label>
<input type="email" class="form-control input-sm" name="email" id="email">
</div>
<div class="form-group">
<label>Usuario</label>
<input type="text" class="form-control input-sm" name="username" id="username">
</div>
<div class="form-group">
<label>Password</label>
<input type="password" class="form-control input-sm" name="password" id="password">
</div>
<div class="form-group">
<label class="checkbox-inline">
<input type="checkbox" name="create_content" id="create_content"> Crea contenido
</label>
<label class="checkbox-inline">
<input type="checkbox" name="active" id="active"> Activo
</label>
</div>
<button type="submit" class="btn btn-sm btn-primary" id="btn_Crear">Create</button>
</form>
Occasionally I'm receiving the TokenmismathException, and I'm not able to post anymore, If I comment out the line //'App\Http\Middleware\VerifyCsrfToken', in the Kernel.php file and try to post, it works, And if I uncomment the same line again 'App\Http\Middleware\VerifyCsrfToken',, now I don't receive the TokenmismatchException, until it stops working.
I'm not using ajax
Does anyone know why this is happening.
We had the exact same problem and never found a good solution. We did find a workaround although.
In your .env file, set the Session storage to Redis (yap, you have to install Redis on your server than). This worked for us, never encountered the same problem again.
Note, this works for us, but it of course is not a solution, merely a work-around until someone found the right solution.

HTML - form acting weird. Not redirecting to URL and using GET instead of POST

I'm a CS student and I have a DB project due in less than 24hrs! This is really annoying because I just need to forms to access my DB. Anyway, I have this form that works perfectly, while the second form does not work. Instead of posting and directing to the correct URL the second form re-loads the current page with the variables in the URL. Anybody have any ideas?
<form role="form" method="post" action="../controller/AddPerson.php">
<div class="box-body">
<div class="form-group">
<label for="newReservationFirstName"> First name</label>
<input type="text" class="form-control" name="newReservationFirstName" placeholder="Enter first name">
<label for="newReservationLastName"> Last name</label>
<input type="text" class="form-control" name="newReservationLastName" placeholder="Enter last name">
<label for="newReservationPhoneNumber"> Phone Number</label>
<div class="input-group">
<div class="input-group-addon">
<i class="fa fa-phone"></i>
</div>
<input type="text" class="form-control" name="newReservationPhoneNum" data-inputmask='"mask": "(999) 999-9999"' data-mask/>
</div><!-- /.input group -->
<label for="newReservationStreetAddress"> Street Address</label>
<input type="text" class="form-control" name="newReservationStreetAddress" placeholder="Enter street address">
<label for="newReservationCity"> City</label>
<input type="text" class="form-control" name="newReservationCity" placeholder="Enter city">
<label for="newReservationState"> State</label>
<select class="form-control" name="newReservationState">
<?php
$result = getTableOrderBy('States','stateName');
while($row = mysql_fetch_array($result)) {
echo "<option value=".$row[stateAbbr].">".$row[stateName]."</option>";
} ?>
</select>
<label for="newReservationZip"> Zip Code</label>
<input type="text" class="form-control" name="newReservationZip" placeholder="Enter zipcode">
</div>
<button type="submit" class="btn btn-success btn-lg">Add New Customer</button>
</div>
</form>
This is the form that doesn't work correctly, both pages exist on the server:
<form role="form" method="post" action="../controller/AddEmployee.php">
<div class="box-body">
<div class="form-group">
<label for="newEmployeeFirstName"> First name</label>
<input type="text" class="form-control" name="newEmployeeFirstName" placeholder="Enter first name">
<label for="newEmployeeLastName"> Last name</label>
<input type="text" class="form-control" name="newEmployeeLastName" placeholder="Enter last name">
<label for="newEmployeePhoneNumber"> Phone Number</label>
<div class="input-group">
<div class="input-group-addon">
<i class="fa fa-phone"></i>
</div>
<input type="text" class="form-control" name="newEmployeePhoneNum" data-inputmask='"mask": "(999) 999-9999"' data-mask/>
</div><!-- /.input group -->
<label for="newEmployeeStreetAddress"> Street Address</label>
<input type="text" class="form-control" name="newEmployeeStreetAddress" placeholder="Enter street address">
<label for="newEmployeeCity"> City</label>
<input type="text" class="form-control" name="newEmployeeCity" placeholder="Enter city">
<label for="newEmployeeState"> State</label>
<select class="form-control" name="newEmployeeState">
<?php
$result = getTableOrderBy('States','stateName');
while($row = mysql_fetch_array($result)) {
echo "<option value=".$row[stateAbbr].">".$row[stateName]."</option>";
} ?>
</select>
<label for="newEmployeeZip"> Zip Code</label>
<input type="text" class="form-control" name="newEmployeeZip" placeholder="Enter zipcode">
<p></p>
<p></p>
<label for="newEmployeeFirstName"> Account Username</label>
<input type="text" class="form-control" name="newEmployeeUsername" placeholder="Enter username">
<label for="newEmployeeLastName"> Account Password</label>
<input type="text" class="form-control" name="newEmployeePassword" placeholder="Enter password">
<label for="newEmployeePhoneNumber"> Social Security Number</label>
<input type="text" class="form-control" name="newEmployeeSocial" placeholder="Enter SSN">
<div class="form-group" name="newEmployeePrivileges">
<br>
Privileges :
<select name="newEmployeePrivileges">
<option value="admin">Admin</option>
<option value="admin">Non-Admin</option>
</select>
</div>
<button type="submit" class="btn btn-success btn-lg">Add New Employee</button>
</div>
</div>
</form>
----------------------------------EDIT ----------------------------------------------
I tried making a another really simple form on some extra space and it still didn't work. I have no idea what could be cause it to do this.
<form method="post" action="post" action="../controller/AddEmployee.php">
<button type="submit" class="btn btn-success btn-lg">Add New Employee</button>
</form>
It could be that the button tag you are using to submit the form is causing it behave strangely. Try swapping out the button tag for an input. So:
<form method="post" enctype="multipart/form-data" action="../controller/AddEmployee.php">
<input type="submit" class="btn btn-success btn-lg" name="submit" >Add New Employee</input>
</form>
Also, I noticed you've included two 'action' attributes in your example form :-)

Categories