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

Boltforms doesn't see database tables not starting with "bolt_" #278

Open
COOLak opened this issue Feb 12, 2019 · 4 comments
Open

Boltforms doesn't see database tables not starting with "bolt_" #278

COOLak opened this issue Feb 12, 2019 · 4 comments

Comments

@COOLak
Copy link

COOLak commented Feb 12, 2019

I've been playing with the database option to store submission data to a separate table, because I don't want to create a contenttype for that, so I manually created a table named boltforms_contact_us, but it came to my attention that the mechanism Boltform uses to query tables ignores tables created manually and always throws an error missing database table 'boltforms_contact_us', even though it's definitely there and contains all appropriate columns. To check my assumption, I dumped $tables, and indeed the list didn't contain manually created tables and only listed those created by Bolt. As I lack PHP knowledge, I've no idea how to fix this myself and I had to remove the part of code that checks if the table exists. As soon as I did this, the form data successfully started to save to my custom table. So I'll have to leave it like that for now, but I really do hope that this issue will be fixed in future versions.

@jadwigo
Copy link
Collaborator

jadwigo commented Feb 12, 2019

By default the core bolt system only knows about tables with the prefix 'bolt_' that are defined in the contenttypes.yml

In boltforms you can save entries to a contenttype or to a custom database table.

If you want to save form submission items to a contenttype you need to make sure that all fields in the boltforms are present in the contenttype, and that all required fields in the database are set as fields in the contactform.

The same is true if you want to save the submission items ot a custom table 'boltforms_contact_us'. You need to make sure that all the fields you define in the contact form boltforms.bolt.yml are present in the 'boltforms_contact_us' .. and that they all have the correct type.

You might need to use the previously documented custom field data providers:
https://github.com/bolt/boltforms/blob/70184cbbdf689f5ad631e80d59a570cc9657ad5f/README.md#custom-field-data-providers

To make sure everything is correct you need to test the form and check if there are no errors in the bolt system log. Add any missing fields when there are errors, and change the fieldtype in the database if needed.

@COOLak
Copy link
Author

COOLak commented Feb 12, 2019

@jadwigo I made sure the fields were there, and of correct type. And there were no errors in Bolt log. The only error was "missing table", but if I remove the check, everything is fine and saves into that table without any warnings/errors.

@COOLak
Copy link
Author

COOLak commented Feb 12, 2019

        if (!$sm->tablesExist([$tableName])) {
            // log failed attempt
            throw new InternalProcessorException(sprintf('Failed attempt to save submission: missing database table `%s`', $tableName), 0, null, false);
        }

Sorry for possible stupidity, as I'm not PHP-savy, but I don't see the point in this part of code at all. If the table doesn't exist, it throws an exception anyway, just with another wording. But when that code is present, it doesn't see custom tables. so it's only better without it. It should be either fixed or removed, and personally I removed it and feel totally okay this way. My forms get saved and that's all that matters.

@COOLak
Copy link
Author

COOLak commented Mar 17, 2019

I just thought, why not make a list of fields that we want to store in db in boltforms.bolt.yml and then form a database table based on those? This way we could create a table even if it didn't exist initially, and the column names would be formed from the names of the fields to be saved. I think how it's done now is a rather head-over-heels approach, when you have to create a table and columns yourself, and then it saves the fields for which it finds columns.

@COOLak COOLak changed the title Boltforms doesn't see database tables created not by Bolt itself Boltforms doesn't see database tables not starting with "bolt_" Mar 19, 2019
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

2 participants