Input:all is not showing the post data. Any clue why? I have already tried Input:all before and I haven't experienced this.
print_r($_POST);
print_r(Input::all());
exit;
Array
(
[_token] => Sr4MSYL2ovDWMtU3o2Ms6YULFcxsuFYtAasS3Vqu
[username] => name
[password] => password
)
Array
(
)
This is my login view. I don't think that this has anything to do with the issue though.
#extends("layout")
#section("content")
{{ Form::open() }}
{{ $errors->first("password") }}<br />
{{ Form::label("username", "Username") }}
{{ Form::text("username", Input::old("username")) }}
{{ Form::label("password", "Password") }}
{{ Form::password("password") }}
{{ Form::submit("login") }}
{{ Form::close() }}
#stop
Related
here is my ContactController.php:
public function destroy($id){
$contact = Contact::find($id);
$contact->delete();
return Redirect::to('http://localhost:8000/contactsview');
}
Here is my rountes.php
Route::delete('/contactsview/destroy/{id}', array('uses'=>'ContactController#destroy'));
Here is my index.blade.php:
{{ Form::open(array('url'=>'/contactsview/delete/'.$contact->id, 'method'=>'DELETE', 'style'=>'display:inline;')) }}
<!-- {{ Form::hidden('id', $contact->id) }} -->
{{ Form::submit('Delete') }}
{{ Form::close() }}
What did I do wrong?
Try the form with this instead, passing in the $contact->id as a param rather than directly in the URL:
{{ Form::open(array('method' => 'DELETE', 'action' => array('ContactController#destroy', $contact->id )) }}
I am trying to update information in my database with Laravel. Not sure what I am doing wrong but I can't seem to find where the problem is. Here is the code for my edit page (This is the page where I would edit information taken from my DB).
{{ Form::open(['url'=>'portfolio/update']) }}
<div>
{{ Form::label('portfolio_title', 'Portfolio Title:') }}
{{ Form::text('portfolio_title',$work->portfolio_title) }}
{{ $errors->first('portfolio_title','<span class="error">:message</span>') }}
</div>
<div>
{{ Form::label('portfolio_description', 'Portfolio Description') }}<br>
{{ Form::textarea('portfolio_description', $work->portfolio_description, ['size' => '50x5']) }}
{{ $errors->first('portfolio_description','<span class="error">:message</span>') }}
</div>
<div>
{{ Form::label('portfolio_content', 'Portfolio Content') }}<br>
{{ Form::textarea('portfolio_content', $work->portfolio_content, ['size' => '50x5']) }}
{{ $errors->first('portfolio_content','<span class="error">:message</span>') }}
</div>
{{ Form::hidden('id',$work->id) }}
<div>
{{ Form::submit('Update Work') }}
</div>
{{ Form::close() }}
I have a controller called PortfolioController that will save info to database and what not.
public function edit($work_title){
$work = Portfolio::wherePortfolio_title($work_title)->first();
return View::make('portfolio/edit', ['work' => $work]);
}
public function update(){
$id = Input::get('id');
$input = Input::except('id');
if( !$this->portfolio->fill($input)->isValid()){
return Redirect::back()->withInput()->withErrors($this->portfolio->errors);
}
$work = Portfolio::find($id);
$work->portfolio_title = Input::get('id');
$work->save();
}
Here is my route that I am working with:
Route::resource('portfolio','PortfolioController');
Route::post('portfolio/update','PortfolioController#update');
I am able to get the form populated with the correct information but when i change something like the title and click update, the page reloads but does not save in the DB. Sometimes I will get an MethodNotAllowedHttpException error. This has been pretty frustrating for me so any help will be greatly appreciated.
Why don't you just actually use your resource route?
First, remove the portfolio/update route. You don't need it.
Then change your Form::open to this:
{{ Form::open(['route' => ['portfolio.update', $work->portfolio_title], 'method' => 'put']) }}
This way you target the update method in your RESTful controller.
Finally change that to use the portfolio_title as identifier and you should be able to remove the hidden id field from your form.
public function update($work_title){}
Please take a look at:
RESTful controllers
Opening a form
Earlier today I had the exact same problem with Auth::attempt always retuning false. I realized that Auth checks for a hashed password, so by doing so I was able to get it to return true, but now it always does. Even if I type asdadfasdfaf in my form, the if statement loads the page. Any suggestions?
Controller:
class userController extends \BaseController
{
public function login()
{
$user = array(
'username' => Input::get('username'),
'password' => Input::get('password')
);
if(Auth::attempt($user))
{
return Redirect::route('home');
}
else
{
return View::make('login');
}
}
}
Form
{{ Form::open(array('url' => 'home' )) }}
{{ Form::label('username', 'Username: ') }}
{{ Form::text('username') }}
</br>
{{ Form::label('password', 'Password: ') }}
{{ Form::password('password') }}
</br>
{{ Form::submit() }}
{{ Form::close() }}
The Routes file:
Route::post('home', 'userController#login');
No matter what I enter it always directs me to my "home" page?
The action url should be login
{{ Form::open(array('url' => 'login' )) }}
^^^^ as you used Auth::attempt to this URL
{{ Form::label('username', 'Username: ') }}
{{ Form::text('username') }}
</br>
{{ Form::label('password', 'Password: ') }}
{{ Form::password('password') }}
</br>
{{ Form::submit() }}
{{ Form::close() }}
I encounter a error:
Some mandatory parameters are missing ("users") to generate a URL for route "users.update".
I have this set on my view:
{{ Form::open( array('action' => array('UsersController#update')) ) }}
<div> {{ Form::label('username', 'Username:') }}
{{ Form::text('username', $user->username , array('class' => 'form-control')) }}</div>
<div> {{ Form::label('email', 'Email Address:') }}
{{ Form::text('email', $user->email , array('class' => 'form-control')) }}</div>
<div> {{ Form::label('new_password', 'New Password:') }}
{{ Form::text('new_password', '', array('class' => 'form-control')) }} </div>
<div> {{ Form::label('old_password', 'Old Password:') }}
{{ Form::text('password', '', array('class' => 'form-control')) }} </div>
{{ Form::submit() }}
{{ Form::close() }}
I also have a function in my controller linked to update:
public function update() {
return 'This is an update';
}
And finally, when I check all the routes available in Artisan command, I found that the update has a route to: users/{users}
What's wrong with my codes? I'm trying to update a user and it throws this error.
Your route is defined in a way to expect a variable $users to be passed. because of the: {users}
Instead, you should define it like:
Route::post('users/update', 'UsersController#update');
and then in your function update() get the post variable by:
$users_data = Input::get();
OR
if you want to keep the parameter, redefine the form by passing additional parameter:
{{ Form::open( array('action' => array('UsersController#update', $id)) ) }}
The way you are opening the FORM, it is needs a route paramenter. If you dont want to pass parameters, just use the following:
{{ Form::open(array('action' => 'UsersController#update')) }}
Instead of:
{{ Form::open( array('action' => array('UsersController#update')) ) }}
Even when you're setting a action, you may still need a route for it. I STRONGLY recommend you to always use CLEARED DEFINED routes to your controllers. See if the Resource Controllers helps you, in case you don't wanna to define every god damm route (I DON'T).
And, finally answering your question: I think a
{{ Form::open(array('action' => 'UsersController#update')) }}
...may solve your problem. Hope it helps. Sorry for my bad english! :D
I'm trying to put two hidden fields in a form for a particular user. I have this code:
<div id="mio_miobundle_empleadotype">
{{ form_row(edit_form.dni) }}
{{ form_row(edit_form.nombre) }}
{{ form_row(edit_form.username) }}
{{ form_row(edit_form.apellido1) }}
{{ form_row(edit_form.apellido2) }}
{{ form_row(edit_form.localidad) }}
{{ form_row(edit_form.provincia) }}
{{ form_row(edit_form.telefono) }}
{{ form_row(edit_form.movil) }}
{{ form_row(edit_form.email) }}
{{ form_row(edit_form.direccion) }}
{% if is_granted('ROLE_A') %}
{{ form_row(edit_form.activo) }}
{{ form_row(edit_form.role) }}
{%endif%}
{{ form_row(edit_form.password) }}
and:
$builder
->add('dni','text',array('label' => 'Dni'))
->add('nombre','text',array('label' => 'Nombre'))
->add('username','text',array('label' => 'Usuario'))
->add('apellido1','text',array('label' => 'Apellido1'))
->add('apellido2','text',array('label' => 'Apellido2'))
->add('email','email',array('label' => 'Email'))
->add('localidad','text',array('label' => 'Localidad'))
->add('provincia','text',array('label' => 'Provincia'))
->add('telefono','text',array('label' => 'Teléfono'))
->add('movil','text',array('label' => 'Móvil'))
->add('direccion','text',array('label' => 'Dirección'))
->add('activo')
->add('role')
->add('password', 'repeated', array('first_name' => 'Nueva contraseña','second_name' => 'Repite contraseña','type' => 'password' ,'invalid_message'=> 'Las contraseñas deben ser iguales.'))
;
}
but I get this error:
Catchable Fatal Error: Argument 1 passed to mio\mioBundle\Entity\Empleado::setRole() must be an instance of mio\mioBundle\Entity\Role, null given, called in /var/www/Symfony/vendor/symfony/src/Symfony/Component/Form/Util/PropertyPath.php on line 347 and defined in /var/www/Symfony/src/mio/mioBundle/Entity/Empleado.php line 289
I say that because I have to fill in the state are any help?
Place the checking role code in the controller
public function someAction()
{
$form = $this->createFrom( // ...
if (false === $this->get('security.context')->isGranted('ROLE_A')) {
$form->remove('activo');
$form->remove('role');
}
// ...
}
And in the template check if form field is defined
{{ edit_form.activo is defined ? form_row(edit_form.activo) : '' }}
{{ edit_form.role is defined ? form_row(edit_form.role) : '' }}
Instead of not rendering the fields completely, try hiding the fields from view using css.
{% if is_granted('ROLE_A') %}
{{ form_row(edit_form.activo) }}
{{ form_row(edit_form.role) }}
{% else %}
{{ form_widget(edit_form.activo, { 'attr': {'class': 'hide'} }) }}
{{ form_widget(edit_form.role, { 'attr': {'class': 'hide'} }) }}
{% endif %}