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
Related
I'm trying to load Bootstrap classes with FormFacade in a view but doesn't work.
I tried this steps: https://stackoverflow.com/a/46392838/3444714
But the Form class is generating fields without the effects of Bootstrap.
<div class="form-group">
{{ Form::label('testField', 'Test:') }}
{{ Form::text('testField', null, ['class' => 'form-control']) }}
<input type="text" id="testField" name="testField" class="form-control" />
</div>
Check my attachment, same code, but the field generated by FormFacade is wrong.
Thank you.
I have customized my register_content.html.twig like that
<form class="form-horizontal" action="{{ path('fos_user_registration_register') }}" {{ form_enctype(form) }} method="POST">
<div id="fos_user_registration_form">
<div class="form-group">
<div class="col-sm-10">
{{ form_widget(form.username, { 'attr': {'class': 'form-control', 'placeholder': 'Pick a username' } }) }}
{{ form_errors(form.username) }}
</div>
</div> ...
And now, when I'm getting an errors, those errors looks like that
fos_user.username.already_used
fos_user.email.already_used
fos_user.password.mismatch
I just want to change those messages, could anyone help me?
Once you enable the translator service, e.g.,
app\config\config.yml:
framework:
translator: { fallback: "%locale%" }
copy the appropriate FOSUserBundle.{locale}.yml from ...vendor/friendsofsymfony/userbundle/Resources/translations to ...app/Resources/translations. In the copied file, change the messages for
fos_user.username.already_used
fos_user.email.already_used
fos_user.password.mismatch
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.
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.