Forums

Save dat to three already existing tables.

rajs 01 Jul, 2015
Hello,

I have a simple form that collects information from the user in front end.
I need to store this information in three different existing DB tables.
There are other ways to add data to these tables from Joomla Backend.

So, I need to check the records in the table and then +1 the primary key Id and then store the data.
Based on what I read in the forum, this should be possible with a custom code.

I assume i will not be using the DBsave feature. But instead a code should execute on submit.


Can your provide a simple sample code that reads existing DB table and that saves the form data to any DB table.
And also point to how or where this code should be put.

I'm a beginner,

Thanks,
rajs 01 Jul, 2015
Hello,

I've seen that before. Not relevant to my current need.
Can the admin help?
GreyHead 01 Jul, 2015
Hi rajs,

As far as I can see you want the FAQ that Prof Calc linked to. The DB Save action - possibly three of them - will do what you need.

Bob
rajs 01 Jul, 2015
Hi Bob,
Here are more details of what I need to do.
The user is submitting a poll using a FE form.
There are two tables, lets say,
Table-1 = Poll id, title
Table-2= Poll id, answer choice
For every form submission, one row is added to table 1, but more than one row can be added to table 2 based on the number choices the FE user selection.
The form looks like this
Titile :
No of poll choices:
Poll choice 1:
Poll choice 2: ….
Only partial poll data is submitted through the form, there will be other default data that I need to hard code on the tables each time the form is submitted.

I don’t see how this can be done with DB save feature. I’d assume I’ll need some coding.
Can you please provide a sample code? Or describe how this can be done with the DB save.
GreyHead 02 Jul, 2015
Hi rajs,

Use one DB Save action to save the record to the main table; after that you will have the new record id in the $form->data[''] array.

Use a Custom Code action to structure the data for the multiple save something like this:
$form->data['answers'] = array(
  [0] => array(
    ['record_id'] => 'xxx',
    ['poll_id'] => 'yyy',
    ['answer_choice'] => 'zzz',
  ),
  [1] => array(
    ['record_id'] => 'xxx',
    ['poll_id'] => 'bbb',
    ['answer_choice'] => 'ccc',
  ),
  . . . 
);


Use a second DB set to Multiple Save with the Model ID 'answers' to save these records to the second table.

Bob
rajs 04 Jul, 2015
Thanks Bob, I managed to get it to work.

I have two chronoform date-pickers in my form. I knoe there are 200 posts here about them.
I don't want to use any different kind of date-picker.

The functionality I need is simple,

My form has 2 date fields
From_date :
To_Date:

The from_start date should be today(). Done, works.
To_Date start date should be today() if start_date is not selected. If start_date is chosen, the To_date start date should be the Start_date chosen.

Can you point me to the correct article that applies to the latest version of chronoform or describe the procedure here.

Thanks,
This topic is locked and no more replies can be posted.