I have a problem with blade. I check if user is log in. If is I pass in two input default value from $user ($user->UserName and $user->UserEmail), if not I pass Input::old().
Before I don't check if user is log in it worked fine. Any suggestions??
The view:
#if($errors->has())
<ul>
#foreach ($errors->all() as $error)
<li class="txt-danger">{{ $error }}</li>
#endforeach
</ul>
#endif
#if(Session::has('message'))
<ul>
<li class="txt-success">{{ Session::get('message') }}</li>
</ul>
#endif
{{ Form::open(array('url'=>'contact', 'name'=>'contactform', 'id'=>'contactform')) }}
<p>
#if(Auth::check())
{{ Form::text('name', $user->UserName, array('id'=>'name') }}
#else
{{ Form::text('name', Input::old('name'), array('id'=>'name', 'placeholder'=>'Twoje imię')) }}
#endif
</p>
<p>
#if(Auth::check())
{{ Form::text('email', $user->UserEmail, array('id'=>'email') }}
#else
{{ Form::text('email', Input::old('email'), array('id'=>'email', 'placeholder'=>'Twój e-mail')) }}
#endif
</p>
<p>
{{ Form::text('subject', Input::old('subject'), array('id'=>'subject', 'placeholder'=>'Temat')) }}
</p>
<p>
{{ Form::textarea('message', Input::old('message'), array('id'=>'message', 'placeholder'=>'Wiadomość', 'rows'=>'0')) }}
</p>
{{ Form::submit('Wyślij wiadomość', array('class'=>'mainBtn', 'id'=>'submit')) }}
{{ Form::close() }}
It looks like you're using the Input facade within your form.
The input facade is used to get the values passed by the form once you've submitted it. If you're wanting to use old values being passed back from the controller back to the form you need to pass those as parameters from the controller. Something like:
return View::make('MyView')->with('old', $oldValues);
The reason you're getting the error "syntax error, unexpected ';' in blade" is because you're using the double curly brace {{ }} when you output the Form::text() AND you're using the Input facade within it, so what php is seeing is something like:
echo "<input type='text' name='email'> valuefrominput;</input>";
Basically, Input::old() is writing a semicolon in the middle of your Form::text() code.
Related
I try to make a registration form in Symfony 3.4 but it makes me mad that I cannot place errors properly.
This is how I render the form itself:
{{ form_start(registrationForm) }}
{{ form_widget(registrationForm) }}
{{ form_end(registrationForm) }}
And the fields are rendered from a custom template, where I declare that errors should appear under the field:
{% block form_row %}
<div class="form-group">
{{ block('form_label') }}
{{ block('form_widget_simple') }}
{{ block('form_error') }}
</div>
{% endblock %}
However all my errors are appearing above the whole form as li elements in an ul element. I tried to add 'error_bubbling' => false but it won't make any difference. (The error messages come form the Assert annotations on the underlying model object.)
What am I doing wrong?
I have a strange issue cause it appeared without changing anything as I remember.
I have done my form like this ( which was working great )
#extends('admin')
#section('content')
{{ BootForm::open(['model'=>$post,'update'=>'posts.update','files'=>'true']) }}
{{ BootForm::text('name','Nom') }}
<div class="form-group">
{{ Form::textarea('content',$post->content,['class'=>'editor','id'=>'editor']) }}
#if($errors->first('content'))
<div class="alert alert-danger">{{ $errors->first('content') }}</div>
#endif
</div>
<div class="form-group">
<input type="file" name="img"/>
#if($errors->first('img'))
<div class="alert alert-danger">{{ $errors->first('img') }}</div>
#endif
</div>
<p>{{ BootForm::submit('Modifier') }}</p>
{{ Bootform::close() }}
#stop
And my route file :
Route::resource('posts','PostsController');
But when I submit my form it goes on :
http://local.dev/posts/4 instead of http://local.dev/myfoldername/public/posts/4
All my others routes are working great ( I have others models )
Thank you for the help
I think the problem is that Laravel is built to be used with virtual host that links on public directory and BootForm may have been coded in the same way.
Try to make a virtual host directly on the public directory so you can access the page with something like
http://something.devinstead of http://local.dev/directory/public
{{ BootForm::open(['model'=>$post,'update'=>'posts.update','files'=>'true']) }}
where is $post->id you must gone "id" controller
when I follow this tutorial: http://symfony.com/doc/current/cookbook/form/form_collections.html
and I render the
<ul class="tags" data-prototype="{{ form_widget(form.tags.vars.prototype)|e }}">
...
</ul>
the prototype stay empty if I put it after the {{ form(form)}} but gets filled If I put it i before the {{ form(form) }} tag. any one an idea why this is and how to solve it.
thanks
The tag {{ form(form) }} is supposed to output all your form, so there is nothing to output after this tag.
If the tag {{ form(form) }} does not output the prototype, then it was not configured right in the form type class.
But if you chose to output prototype by using form_widget, you should not use form(form) and should output the form by parts:
{{ form_start(form) }}
{{ form_errors(form) }}
<div>
{{ form_row(form.another_form_property) }}
</div>
<div>
<ul class="tags" data-prototype="{{ form_widget(form.tags.vars.prototype)|e }}">
...
</ul>
</div>
{{ form_end(form) }}
I have a form for adding comments, and i want to know how can i multiply this form on the same page.
I tried this code but it does not work :
{% for statut in statuts %}
<div>
{{ statut.sujet }}
<form action="" method="post" {{ form_enctype(formC) }}>
{{ form_errors(formC) }}
{{ form_errors(formC.commentaire) }}
{{ form_widget(formC.commentaire) }}
<div><input type="submit" class="btn btn-info"/><div>
{{ form_rest(formC) }}
</form>
</div>
{% endfor %}
Does somebody know how to do that ? or any suggestions
You need to do this in the controller like get all statuts then run a for loop for each statuts and get comment form for each statut field store them in array and return the array.
In your twig template then run a for loop for the same.
I am defining my own twig layout for new user registration and I have everything laid out the way I want it with the exception of the plainPassword field from the FOSUserBundle.
<p class="left">
{{ form_widget(form.plainPassword) }}
</p>
<div class="clearfix"></div>
The code above displays both the password and verification block. I would like to break this up into the 4 elements of form.plainPassword.label, form.plainPassword.field, form.plainPassword2.label, and form.plainPassword2.field. I cannot figure out what to put in the form_label() and form_widget() calls.
<p class="left">
{{ form_label( ??? ) }}
{{ form_widget( ??? ) }}
</p>
<p class="left">
{{ form_label( ??? ) }}
{{ form_widget( ??? ) }}
</p>
<div class="clearfix"></div>
I am assuming this can be done.
I had the same problem. My solution (seems to be official :) :
{{ form_label (form.plainPassword.first) }}
{{ form_widget (form.plainPassword.first) }}
{{ form_label (form.plainPassword.second) }}
{{ form_widget (form.plainPassword.second) }}
Hope it can helps !
This blog post shows how to output a repeated field in twig.
http://blogsh.de/2011/10/19/how-to-use-the-repeated-field-type-in-symfony/
But in short this worked for me:
{{ form_label (form.plainPassword.children['New Password']) }}
{{ form_widget (form.plainPassword.children['New Password']) }}
{{ form_label (form.plainPassword.children['Confirm Password']) }}
{{ form_widget (form.plainPassword.children['Confirm Password']) }}
I have to say I'm sure using .children isnt the best/official way of doing it, but it works!