laravel5 form not displayed on browser - forms

My register.blade.php file -
{{ Form::open(array('url'=>'register'))}}
{{ Form::label('email','Email Address')}}
{{ Form::text('email')}}
{{ Form::label('username','Username')}}
{{ Form::text('username')}}
{{ Form::label('password','Password')}}
{{ Form::password('password')}}
{{ Form::submit('Sign up')}}
{{ Form::close()}}
But I have get raw html form on bowser window with html tags i.e form not created

In Laravel 5 the blades changed. You need to use {!! !!} if you want to post unescaped text
{!! Form::open(array('url'=>'register')) !!}
{!! Form::label('email','Email Address') !!}
{!! Form::text('email') !!}
{!! Form::label('username','Username') !!}
{!! Form::text('username') !!}
{!! Form::label('password','Password') !!}
{!! Form::password('password') !!}
{!! Form::submit('Sign up') !!}
{!! Form::close() !!}

Related

TokenMismatchException when posting a form using laravel5.4

TokenMismatchException in VerifyCsrfToken.php line 68,when i try to post a form.
<form method="post" action="url('add')" >
{{ csrf_field() }}
<input type="text" name="title" />
<input type="submit" value="Add" />
</form>
Its was working fine before i added this package.
Instead of {{ Form::open() }} either you can manually add hidden input field in the form just like Andranik Petrosyan suggested
But still I would like you to try
{!! csrf_field() !!} instead of {{ csrf_field() }}
If you don't use Laravel Form, for example:
{!! Form::open([]) !!}
{!! Form::close() !!}
you can use:
<input type="hidden" name="_token" value="{{ csrf_token() }}">
Sometimes you need to clear your cache as well.

Laravel submit doesn't work when form is in different containers

I'm working on a Laravel 5.3 project and I'm in the process of deploying to a staging server. For staging I used latest Laravel(5.4). Now, one of the problems is that locally, a form which is spread on some table cells is working, but on the staging version the submit button doesn't do anything (like it not part of the form).
<tbody>
{!! Form::model($job = new \App\Models\Job, ['url' => 'admin/job']) !!}
{!! Form::hidden('person', $person->id) !!}
<tr>
<td colspan="3" class="form-group">
{!! Form::text('name', null, ['class' => 'form-control']) !!}
</td>
<td class="form-group">
{!! Form::submit('Adauga', ['class' => 'btn btn-primary form-control']) !!}
</td>
</tr>
{!! Form::close() !!}
#foreach($jobs as $job)
<tr> ....
On inspector both version are displaying the form opening and closing on the same line, but the local variant does send the request.
html in inspector:
Does dividing a form's inputs in different containers is sloppy?

Anchor error on form - Symfony3/Materialize

Using Symfony 3.2 && PhpStorm.2016.3.2 on Ubuntu 16.04
I have a problem that I partially resolved on the phone number field in this twig form.
I use materialize as the framework css for this project and I use the form of this framework.
I would like to be able to anchor the view directly on the form after an error has been spotted. So far it works great with the phone number section but anyone else doesn't work. I tried to tweak my code as much as I can but still I cannot anchor my view on other fields that get an error. It is pretty much frustrating.
here is the form twig in the view
<form class="col m12" method="POST">
{{ form_start(form) }}
<div class="row" id="radio-button-block">
<div class="col m12">
{{ form_row(form.baptismChoice) }}
</div>
</div>
<div class="row">
<div class="input-field col s6 validate" id="last_name" type="text">
{% if form.vars.errors|length %}
{{ form_row(
form.lastName,
form.lastName.vars|merge({'attr': {'autofocus': null}})
)
}}
{% else %}
{{ form_row(form.lastName) }}
{% endif %}
</div>
<div class="input-field col s6 validate" id="first_name" type="text">
{% if form.vars.errors|length %}
{{ form_row(
form.firstName,
form.firstName.vars|merge({'attr': {'autofocus': null}})
)
}}
{% else %}
{{ form_row(form.firstName) }}
{% endif %}
</div>
</div>
<div class="row">
<div class="input-field col s12 validate" id="email" type="email">
{{ form_row(form.authorEmail) }}
</div>
</div>
<div class="row">
<div class="input-field col s12 validate" id="icon_telephone" type="tel">
{{ form_errors(form) }}
{% if form.vars.errors|length %}
{{ form_row(
form.authorPhone,
form.authorPhone.vars|merge({'attr': {'autofocus': null}})
)
}}
{% else %}
{{ form_row(form.authorPhone) }}
{% endif %}
</div>
</div>
<div class="row">
<div class="input-field col s12 validate" id="city" type="text">
{{ form_row(form.city) }}
</div>
</div>
<div class="row" id="comment-block">
<div class="input-field col s12">
<div id="textarea">
{{ form_row(form.comment) }}
</div>
</div>
</div>
<div class="row">
<div class="input-field col s12 center-align">
{{ form_row(form.submit) }}
</div>
</div>
{{ form_end(form) }}
</form>
and here the Form builder in FomrType.php
->add('firstName', TextType::class, array(
'label' => 'Prénom',
'required' => true,
'attr' => array(
'class' => 'validate',
'id' => 'first_name',
),
'constraints' => array(new Regex(
array(
'pattern' => "#^[a-zéèàêâùïüë' -]{2,}$#i",
'message' => 'Oops ! Ce champ n\'est pas bon.'
)
)),
))
->add('lastName', TextType::class, array('constraints' => new Regex("#^[a-zéèàêâùïüë' -]{2,}$#i"),
'label' => 'Nom',
'required' => true,
'attr' => array(
'class' => 'validate',
'id' => 'last_name',
),
))
->add('authorEmail', EmailType::class, array('label' => 'Adresse mail',
'required' => true,
'attr' => array(
'class' => 'validate',
'if' => 'email'
),
))
->add('authorPhone', TextType::class, array(
'label' => 'Numéro de téléphone',
'required' => true,
'error_bubbling' => true,
'attr' => array(
'class' => 'validate',
'id' => 'icon_telephone'
),
'constraints' => array(new Regex(
array(
'pattern' => '#^0[1-9]([-. ]?[0-9]{2}){4}$#',
'message' => 'Oops ! Ce champ n\'est pas bon.'
)
)),
))
does anyone have an idea?
You're checking if the whole form has the errors set {% if form.vars.errors|length %}, but you should check if the specific field has an error {% if form.field_name.vars.errors|length %}.
In your present code, when an error occurs on any one of the fields, then autofocus is set on all of your fields and browser sets and scrolls to the first one.

Laravel FORM::select not being displayed in webpage

when creating the register page I am trying to pass in an array from the database ('id' and 'name') into a select field box on the register form but it wont display anything, its really bazar, when I inspect it in the browser I can see the div container and all of the options correctly in proper fields but for some reason there is no select field (total not visible in the browser) lol, I tried it with hard coded values and values from db and nothing is getting the select field to work, any help is greatly appreciated!
login.blade.php
#extends('layouts.main')
#section('content')
<div class="page-footer" id="contactus">
<div class="container">
<div class="row" align="center">
<div class="col 16 s12">
<h4 class="black-text">Account Center</h4>
</div>
</div>
<div class="row" style="margin-bottom: 0px;">
<div class="col 16 s12 m6" align="center">
<h5 class="black-text">Login</h5>
{!! Form::open(['method'=>'POST', 'action'=>'UsersController#store', 'class'=>'pure-form pure-form-stacked']) !!}
<br/>
<div class="input-field">
<i class="material-icons prefix fa fa-at"></i>
{!! Form::label('loginEmail', 'E-mail') !!}
{!! Form::email('loginEmail', null, ['class'=>'form-control'])!!}
</div>
<div class="input-field">
<i class="material-icons prefix fa fa-key"></i>
{!! Form::label('loginPassword', 'Password') !!}
{!! Form::password('loginPassword', ['class'=>'form-control'])!!}
</div>
<div class="form-group">
{!! Form::button('<i class="material-icons left fa fa-send"></i>Login', ['type' => 'submit', 'class'=>'waves-effect waves-light btn']) !!}
</div>
{!! Form::close() !!}
<br/><br/>
</div>
<div class="col 16 s12 m6" align="center">
<h5 class="black-text">Register</h5>
{!! Form::open(['method'=>'POST', 'action'=>'UsersController#store', 'class'=>'pure-form pure-form-stacked']) !!}
<br/>
<div class="input-field">
<i class="material-icons prefix fa fa-at"></i>
{!! Form::label('registerEmail', 'E-mail') !!}
{!! Form::email('registerEmail', null, ['class'=>'form-control'])!!}
</div>
<div class="input-field">
<i class="material-icons prefix fa fa-key"></i>
{!! Form::label('registerPassword', 'Password') !!}
{!! Form::password('registerPassword', ['class'=>'form-control'])!!}
</div>
<div class="input-field">
<i class="material-icons prefix fa fa-key"></i>
{!! Form::label('confirm', 'Confirm Password') !!}
{!! Form::password('confirm', ['class'=>'form-control'])!!}
</div>
<div class="input-field">
<i class="material-icons prefix fa fa-building"></i>
{!! Form::label('role_id', 'Role') !!}
</br>
{!! Form::select('role_id', [''=>'Choose Option'] + $organizationTypes, null, ['class'=>'form-control', 'style'=>' resize:vertical; ', 'id' => 'industryId'])!!}
</div>
</br>
</br>
</br>
</br>
<div class="input-field">
<i class="material-icons prefix fa fa-building"></i>
{!! Form::label('organizationName', 'Organization Name') !!}
{!! Form::password('organizationName', ['class'=>'form-control'])!!}
</div>
<div class="form-group">
{!! Form::button('<i class="material-icons left fa fa-send"></i>Register', ['type' => 'submit', 'class'=>'waves-effect waves-light btn']) !!}
</div>
{!! Form::close() !!}
<!-- loading spinner -->
<div class="preloader-wrapper active" id="sendEmailLoader">
<div class="spinner-layer spinner-yellow-only">
<div class="circle-clipper left">
<div class="circle"></div>
</div>
<div class="gap-patch">
<div class="circle"></div>
</div>
<div class="circle-clipper right">
<div class="circle"></div>
</div>
</div>
</div>
<!-- end loader -->
</form>
<br/><br/>
</div>
</div>
</div>
</div>
#endsection
AuthController.php
<?php
namespace App\Http\Controllers\Auth;
use App\OrganizationType;
use App\User;
use Validator;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ThrottlesLogins;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
class AuthController extends Controller
{
/*
|--------------------------------------------------------------------------
| Registration & Login Controller
|--------------------------------------------------------------------------
|
| This controller handles the registration of new users, as well as the
| authentication of existing users. By default, this controller uses
| a simple trait to add these behaviors. Why don't you explore it?
|
*/
use AuthenticatesAndRegistersUsers, ThrottlesLogins;
/**
* Where to redirect users after login / registration.
*
* #var string
*/
protected $redirectTo = '/users';
/**
* Create a new authentication controller instance.
*
* #return void
*/
public function __construct()
{
$this->middleware($this->guestMiddleware(), ['except' => 'logout']);
}
/**
* Get a validator for an incoming registration request.
*
* #param array $data
* #return \Illuminate\Contracts\Validation\Validator
*/
protected function validator(array $data)
{
return Validator::make($data, [
'email' => 'required|email|max:255|unique:users',
'password' => array(
'required',
'min:6',
'confirmed',
'regex:/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*(_|[^\w])).+$/'
),
'organizationType' => 'required',
'organizationName' => 'required|max:255',
]);
}
/**
* Create a new user instance after a valid registration.
*
* #param array $data
* #return User
*/
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
]);
}
public function getLogin()
{
//
$organizationTypes = OrganizationType::lists('name','id')->all();
//return $organizationTypes;
return view('auth.login', compact('organizationTypes'));
}
}
routes.php
Route::get('/login', 'Auth\AuthController#getLogin');
method lists() is deprecated, use pluck() instead.
to get your select do this:
In your controller first change lists() to pluck() (i hope you have laravel version 5.2+)
$organizationTypes = OrganizationType::pluck('name','id')->toArray();
and in view do this
{!! Form::select('role_id', $organizationTypes, null, ['class'=>'form-control'])!!}
update
OK you are using css template materialize and because of template you need to append right class for select box...this will work but probably needs some other classes too:
{!! Form::select('role_id', $organizationTypes, null, ['class' => 'browser-default', 'placeholder' => 'Choose Option'])!!}
{!! Form::label('role_id', 'Organization name') !!}

Display pure html code in tinymce laravel

Hi I am using tinmymce in laravel5. I create blogposts where i need to display code snippets.
for example i want to display this bit of code snippet <meta http-equiv="X-UA-Compatible" content="IE=edge"> and here is my source code as seen in tinymce:
<pre><code><meta http-equiv="X-UA-Compatible" content="IE=edge"></code></pre>
And this is how it is saved in my database:
<pre><code><meta http-equiv="X-UA-Compatible" content="IE=edge"></code></pre>
The problem is when i pull that data to edit in my view using the same tinymce editor
I see nothing, its blank. if i check the source code all is left there is <pre></pre>
Here is my create page:
#extends('layouts.app')
#section('content')
<section class="articles-show">
<div class="container">
<div class="row">
<div class="col-sm-10 articles-page">
<h1>Create Article</h1>
{{-- #if (Auth::user()->isAuthor() || Auth::user()->isAdmin()) --}}
{!! Form::open(['method' => 'POST', 'action' => 'ArticlesController#store', 'files' => true]) !!}
#include('partials.error-message')
<div class="form-group">
{!! Form::label("title", "Title:") !!}
{!! Form::text("title", null, ['class' => 'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label("body", "Body:") !!}
{!! Form::textarea("body", null, ['class' => 'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('photo_id', 'Featured Image:') !!}
{!! Form::file('photo_id', array('class' => 'form-control')) !!}
</div>
<div class="form-group">
{!! Form::label("category_id", "Category:") !!}
{!! Form::select("category_id[]", $categories, null, ['id' => 'tag_list', 'class' => 'form-control', 'multiple']) !!}
</div>
<div class="form-group">
{!! Form::label("meta_desc", "Meta Description:") !!}
{!! Form::text("meta_desc", null, ['class' => 'form-control']) !!}
</div>
<div class="form-group">
{!! Form::submit("Create Article", ['class' => 'btn btn-primary']) !!}
</div>
{!! Form::close() !!}
{{-- #endif --}}
</div>
<div class="col-sm-2 articles-page">
{!! Form::open(['method' => 'POST', 'action' => 'CategoryController#store']) !!}
<br>
<div class="form-group">
{!! Form::label("name", "Category Name:") !!}
{!! Form::text("name", null, ['class' => 'form-control']) !!}
</div>
<div class="form-group">
{!! Form::submit("Create Category", ['class' => 'btn btn-primary']) !!}
</div>
{!! Form::close() !!}
</div>
</div>
</div>
</section>
#include('partials.select-2-script')
#include('partials.tinymceScript')
#endsection
Here is my edit page:
#extends('layouts.app')
#section('content')
#section('content')
<section class="articles-show">
<div class="container">
<div class="row">
<div class="col-sm-10 articles-page">
<h1>Create Article</h1>
{!! Form::model($article, ['method' => 'PATCH', 'action' => ['ArticlesController#update', $article->id], 'files' => true]) !!}
#include('partials.error-message')
<div class="form-group">
{!! Form::label("title", "Title:") !!}
{!! Form::text("title", null, ['class' => 'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label("body", "Body:") !!}
{!! Form::textarea("body", null, ['id' => 'mytextarea', 'class' => 'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('photo_id', 'Featured Image:') !!}
{!! Form::file('photo_id', array('class' => 'form-control')) !!}
</div>
<div class="form-group">
{!! Form::label("category_id", "Category:") !!}
{!! Form::select("category_id[]", $categories, null, ['id' => 'tag_list', 'class' => 'form-control', 'multiple']) !!}
</div>
<div class="form-group">
{!! Form::label("meta_desc", "Meta Description:") !!}
{!! Form::text("meta_desc", null, ['class' => 'form-control']) !!}
</div>
<div class="form-group">
{!! Form::submit("Edit Article", ['class' => 'btn btn-primary']) !!}
</div>
{!! Form::close() !!}
{!! Form::open(['method' => 'DELETE', 'action' => ['ArticlesController#destroy', $article->id]]) !!}
<div class="form-group">
{!! Form::submit("Delete Article", ['class' => 'btn btn-danger']) !!}
</div>
{!! Form::close() !!}
</div>
<div class="col-sm-2 articles-page">
{!! Form::open(['method' => 'POST', 'action' => 'CategoryController#store', 'files' => true]) !!}
<br>
<div class="form-group">
{!! Form::label("name", "Category Name:") !!}
{!! Form::text("name", null, ['class' => 'form-control']) !!}
</div>
<div class="form-group">
{!! Form::submit("Create Category", ['class' => 'btn btn-primary']) !!}
</div>
{!! Form::close() !!}
</div>
</div>
</div>
</section>
#include('partials.select-2-script')
#include('partials.tinymceScript')
#endsection
and here is my tinymce script page that is in partials which i have included in create and edit pages:
<script src="http://code.jquery.com/jquery.js"></script>
<script src="//cdn.tinymce.com/4/tinymce.min.js"></script>
<script>
var editor_config = {
path_absolute : "{{ URL::to('/') }}/",
selector: "textarea",
//entities : "60,lt,62,gt,38,amp",
// entity_encoding: "raw",
plugins: [
"advlist autolink lists link image charmap print preview hr anchor pagebreak",
"searchreplace wordcount visualblocks visualchars code fullscreen",
"insertdatetime media nonbreaking save table contextmenu directionality",
"emoticons template paste textcolor colorpicker textpattern spellchecker"
],
toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image media | spellchecker",
menubar: "tools",
relative_urls: false,
file_browser_callback : function(field_name, url, type, win) {
var x = window.innerWidth || document.documentElement.clientWidth || document.getElementsByTagName('body')[0].clientWidth;
var y = window.innerHeight|| document.documentElement.clientHeight|| document.getElementsByTagName('body')[0].clientHeight;
var cmsURL = editor_config.path_absolute + 'laravel-filemanager?field_name=' + field_name;
if (type == 'image') {
cmsURL = cmsURL + "&type=Images";
} else {
cmsURL = cmsURL + "&type=Files";
}
tinyMCE.activeEditor.windowManager.open({
file : cmsURL,
title : 'Filemanager',
width : x * 0.8,
height : y * 0.8,
resizable : "yes",
close_previous : "no"
});
}
};
tinymce.init(editor_config);
<!-- -->
</script>
I have searched everywhere, tried everything posted in tinymce forums etc. Stackoverflow is my last hope :)
Use :
{!! $varable !!}
this will echo the value for Html engine and Tinymce
Don't use:
{{$variable}}
I've spent half a day trying to solve it and finally I've figured out that here is the problem with textarea and Blade, not with tinyMCE. If you are using something like
<textarea calss="js-wysiwyg">
{{ $blog->text }}
</textarea>
and the blog text contains some html tags like <pre>, <input> or <form>, textarea will do a bit of magic with it and after tinyMCE initializing you will end up with very strange output (nothing outputted in your case and rendered html input in mine :) ). So, you have 2 different options:
<textarea calss="js-wysiwyg">
{{ htmlentities($blog->text) }}
</textarea>
or
<div contenteditable="true" calss="js-wysiwyg">
{{ $blog->text }}
</div>
Variant with htmlentities is better because you don't need to create some jQuery solution for passing value of the div in request (because divs don't have 'name' attributes)
Hope this will help someone!