Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Field [field_name] already exists in the form #545

Open
xorock opened this issue Jul 30, 2019 · 4 comments
Open

Field [field_name] already exists in the form #545

xorock opened this issue Jul 30, 2019 · 4 comments

Comments

@xorock
Copy link

xorock commented Jul 30, 2019

I'm using latest Laravel and this package (fresh install).

<?php

namespace App\Forms;

use Kris\LaravelFormBuilder\Form;
use Kris\LaravelFormBuilder\Traits\ValidatesWhenResolved;

class SongForm extends Form
{
    use ValidatesWhenResolved;

    public function buildForm()
    {
        $this
            ->add('ds', 'date', [
                'rules' => 'required',
            ]);
        $this
            ->add('submit', 'submit', ['label' => 'Save form'])
            ->add('clear', 'reset', ['label' => 'Clear form']);
    }
}
class TestController extends Controller
{
    use FormBuilderTrait;

    public function index(Request $request)
    {
        $form = $this->form(SongForm::class, [
            'method' => 'POST',
            'url' => route('payment.test')
        ]);

        if ($form->isValid()) {
            dd($form->getFieldValues());
        }

        return view('home', [
            'form' => $form
        ]);
    }
}

When all fields are valid I get message Field [ds] already exists in the form App\Forms\SongForm. If I remove trait ValidatesWhenResolved then I get all the data.

@rudiedirkx
Copy link
Collaborator

Sounds like buildForm() is called twice. I don't know ValidatesWhenResolved. @kristijanhusak ?

@vince83110
Copy link
Contributor

@rudiedirkx
Copy link
Collaborator

No, ValidatesWhenResolved has been around for a while, but I don't use it, so I don't know anything about it. @kristijanhusak or @mikeerickson might.

@bm2ilabs
Copy link

Please check your view file you might be calling ds twice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants