scan5415 / grav-plugin-form-database

MIT License
15 stars 10 forks source link

getting an Undefined variable: fieldnames error #1

Open rlynjb opened 7 years ago

rlynjb commented 7 years ago

Hi guys, Idk if this is a bug inside of plugin but I kept getting this error.. it seems like variable fieldnames is undefined.. Im looking at code and i dont know where fieldnames is defined

scan5415 commented 7 years ago

Hi Could you please provide me your database configuration in the process part of your form settings?

Thx

ramono commented 7 years ago

I'm having the same error, my db config is this:

    - database:
        db: grav
        table: contacts
        fields: { name: name, email: email, message: message }

Thanks

scan5415 commented 7 years ago

Could you please provide me the exact error message. and where you get this.

ramono commented 7 years ago

Whoops \ Exception \ ErrorException (E_NOTICE) Undefined variable: fieldnames

Here's a zip file with the whole thing if that helps error file

scan5415 commented 7 years ago

Thanks for the infos. I guess it is an bug.

Workaround Add the following line after line 83 in the file /user/plugins/form-database/form-database.php:

$fieldnames = "";

ramono commented 7 years ago

Now I get

Undefined index: name

And it's pointing to line 110 of the plugin

$fieldvalues = "('" . $_POST[$val] ."'";
scan5415 commented 7 years ago

I'm testing it at the weekend.

ramono commented 7 years ago

I've found the problem.

The form plugin is generating the fields using the following:

form:
    fields:
        - name: name

But the fields are coming up in the form as:

<input name="data[name]" value="" type="text">

So $_POST[$val] wasn't finding anything, I've changed it to $_POST['data'][$val] and it works now.

I don't know if this was a change in the form plugin or if it's going to be permanent, but at least I've got it working.

MattAppleton commented 7 years ago

Just to say a big thanks to ramono — your edit seems to work, I was encountering the exact same issue... would be a great help if the grav-hosted plugin is updated...

codebakery-ch commented 7 years ago

also for me, had to make the edit suggested by @ramono.

I made a PR

Edit: I am not sure this is needed, there is {% set scope = scope ?: 'data.' %} in the form.html.twig