adamwathan / bootforms

Rapid form generation with Bootstrap 3 and Laravel.
MIT License
417 stars 103 forks source link

OldInput laravel #67

Closed realtwister closed 9 years ago

realtwister commented 9 years ago

Hi,

I can't seem to get the oldinput to work in laravel i have this form

<?php $formTypeEdit=true; ?>
            {!! BootForm::openHorizontal($columnSizes)->put() !!}
            {{--{!! BootForm::bind($user) !!}--}}
            <h1>Edit User</h1>

                <?php if($formTypeEdit){ ?>
                {!! BootForm::hidden('id') !!}
                <?php }?>
                {!! BootForm::email(trans('user.fields.email'), 'email') !!}
                <?php if(!$formTypeEdit){?>
                {!! BootForm::password(trans('user.fields.password'), 'password') !!}
                {!! BootForm::password(trans('user.fields.confirm_password'),'password_confirmation') !!}
                <?php }?>
                {!! BootForm::text(trans('user.fields.firstname'),'firstname') !!}
                {!! BootForm::text(trans('user.fields.lastname'),'lastname') !!}
            {!! BootForm::submit('edit') !!}
            {!!  BootForm::close() !!}

should i add something to it to get it to work or should it work out of the box?

Thanks in advance,

adamwathan commented 9 years ago

Can you post the code from the controller where the form is being submitted?

realtwister commented 9 years ago

wow quick response, simple return view for time being

public function update(Request $request, $user)
    {

        if(!is_null($user)){
            return view('dashboard.users.edit', compact('user'));
        }
        return redirect()->route('users')->withErrors(['master'=>trans('user.errors.not_found')]);
    }
adamwathan commented 9 years ago

Try this!

return redirect()->route('users')->withErrors(['master'=>trans('user.errors.not_found')])->withInput();
realtwister commented 9 years ago

That's actually redirecting to the users index page, not to the form. The only thing the controller is doing is loading the form view nothing else at the moment. if(!is_null($user)){ is to check wether the user which is selected by the url is found. You can read it like the controller only does

public function update(Request $request, $user)
    {
            return view('dashboard.users.edit', compact('user'));
    }

hope i'm not too much of a hassle

adamwathan commented 9 years ago

Ah ok, well any time you are showing a view and you want the old input to be shown, you need to flash the input to the session.

What code path is it taking where you would want to show the old input?

Is it really old input you are talking about, or is it form model binding? If it's the binding, you need to change this line:

{{--{!! BootForm::bind($user) !!}--}}

to this:

{{ BootForm::bind($user) }}

It won't actually render anything to the template :+1: Your current version isn't doing the binding because you have it wrapped in the Blade comment tags, which strips it out before compiling if I'm not mistaken.

realtwister commented 9 years ago

Thanks so much the flashing worked, guess i overlooked that part or something.. The comment tags were actualy for testing purposes. It works great now!

Thanks so much for the help and the library! i love it!

adamwathan commented 9 years ago

Awesome! No worries :)