Extending Concrete 5.7 Form block and write data into new mySQL tables
I am creating a customized form with concrete 5.7 default form block. What I am trying to achieve is getting the default form block to write into a new mySQL table.
So far I am able to get the btForm table to write into a new mySQL table i.e btFormExtend. Data from form name and message display fields are appearing in "btFormExtend" table when I save the information from the "options" tab.
However when it comes to creating form questions I am experiencing difficulties in getting the data to write into a new SQL table and once after pressing "Add Question" button the data is sent to the default table of btFormQuestions which is not what I am looking for as a result.
I've modified the class Controller extends Block controller variables as such
public $btTable = 'btFormExtend';
public $btQuestionsTablename = 'btFormExtendQuestions';
public $btAnswerSetTablename = 'btFormExtendAnswerSet';
public $btAnswersTablename = 'btFormExtendAnswers';
but the data still unable to write into the new btFormExtendQuestions table.
Can any concrete 5.7 developer give some pointers in what I am missing?
I packaged this up, creating it's own dashboard pages as well. I found it was really just a case of hunting through all the form block's code and finding where it doing the inserts and updates.
Many of the references to the tables are actually in mini_survey.php, hardcoded into the SQL statements. Not a big deal at all to change over, but the form block gives the impression that the variables at the top with the table names change everything, but that's simply not the case.
So check out mini_survey.php and do some searches for the original table names like btFormQuestions.
The other thing to be aware of is that in block's controller it creates MiniSurvey objects - when you are creating your own copy of the MiniSurvey class, you need to make sure you call it in correctly using the namespacing you have given it - otherwise when you call $miniSurvey = new MiniSurvey(); in your new block's controller you're still going to be referencing the built in MiniSurvey class, not your custom one.
You'd need to do something like this instead:
$miniSurvey = new \Concrete\Package\CustomForm\Block\CustomForm\MiniSurvey();
does the new reference file path as you have indicated for $miniSurvey works in the application\blocks folder as:
$miniSurvey = new \Application\Block\FormExtend\MiniSurvey();
I find the form is still writing on btFormQuestions.
Thanks in advance.
I think it's a good idea to do so, because you may also need to create a custom email template (I updated mine to be an HTML email for example), and maybe some dashboard pages to get the data out somehow.
I've managed to figure out how to get the $miniSurvey function to write into new tables with extended columns.
However I'm facing another problem when adding questions after the approved versions I find concrete 5.7 creating a duplicate of previous questions after clicking the "Save" button. There is duplicated rows but extended columns in the mySQL updates as "Null".
How do I stop the duplicates or at least make sure the data is retained when there were input field questions saved previously?