Open COOLak opened 5 years ago
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.
@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.
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.
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.
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 namedboltforms_contact_us
, but it came to my attention that the mechanism Boltform uses to query tables ignores tables created manually and always throws an errormissing 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.