Forums

Edit table records created with multiplier

awgcas 22 Mar, 2017
Hi,
I am developing a simple form to submit papers for a conference. I have 4 tables: paper, author, topic and papertopic.
As a paper may have an undefined number of authors, in my submit form I decided to use the multiplier feature. For each author I have the following fields: id_paper, first_name, last_name, email, and so on.
Everything is working fine when I submit data, the problem comes out if I want to edit a submission; I am able to retrieve all other info from other tables correctly, but not for author table.

How can I get a number of "multiplied" containers equal to number of authors submitted? And how can I fill the "multiplied" authors fields?

Thank you in advance!
Regards,
Alessandro
GreyHead 22 Mar, 2017
Hi Alessandro,

You should be able to use a DB Read action with the Multi read set to Yes to load the Author data and the Model ID to be the same as the DataPath for the Multiplier.

I'm not sure if that will automatically load the right number of copies of the multiplier - please try it and see. If it doesn't then you will need a little custom code to override the default value of the 'Start Count.

Bob
awgcas 22 Mar, 2017
Hi Bob, using the Debugger I am already able to get the records requested, with the correct Model ID (I think ...), but the related fields are empty!!

For example, just to clarify:
author_table[__N__][last_name] is where I store the last name of author.

And this is what I get with the DB Read:
 [author_table] => Array
        (
            [0] => Array
                (
                    [position] => 1
                    [last_name] => bbb
                    [first_name] => aaa
                    [organization] => WWW
                    [country] => AF
                    [email] => uno@qqq.com
                )

        )

This is a simple case with just one author (position is the "author number" in the multiplier submission). Start count is 1, as I suppose that I must have one author at least.
Well, also in this simple case the fields in Author #1 group are empty.

Thank you for you support
Alessandro
GreyHead 22 Mar, 2017
Hi Alessandro,

Please try this in a Custom Code action after the DB Read and before the HTML (render form) action
<?php
$temp = array();
foreach ( $form->data['author_table']  as $a ) {
  $temp[$a['position']] = $a;
}
$form->data['author_table'] = $temp;
?>
This should reorganise the array so that the index numbers match the multiplier numbers.

Bob
awgcas 22 Mar, 2017
Thank you Bob, it works now! I did not realize that index numbers had to match multiplier numbers.

So last problem to be solved is how I can modify the Start count parameter "on-the-fly" to match the number of authors for that paper ...

Any ideas?

Thanks again
Alessandro
GreyHead 23 Mar, 2017
Hi Alessandro,

I think that you can use the technique in this FAQ to set the value dynamically.

You need to set the value to the length of the array: count($form->data['author_table'])

Bob
awgcas 23 Mar, 2017
Hi Bob,
I'm sorry but I do not understand ...
In the FAQ I read:


the ### needs to be replaced by the id of the action you want to configure, this is the number that shows in the Setup tab just after the action title.

the 'parameter_name' needs to be the name of the parameter you want to change - you can check the page HTMl to see what this is.



Start count parameter isn't available in the Setup tab, it is in the Designer tab. I have searched in the code generated:


<?php for($i = 1; $i < 2; $i++): ?>
<?php echo str_replace("__N__", $i, $multiplier_code); ?>
<?php endfor; ?>


The Start count parameter is in the condition $i < 2 (in this situation Start count was = 1, with only one author), so the for cycle stops correctly at $i = 1.

Thanks
Alessandro
GreyHead 23 Mar, 2017
Hi Alessandro,

My apologies, I had forgotten that setting was in the Designer tab and not the Setup tab. I'll have to take a look at the code and see if I can get a version to work there too.

Bob
GreyHead 23 Mar, 2017
Hi Alessandro,

Please try adding author_table to the Data path box in the Multiplier settings for the Multiplier Container element - ChronoForms should then automatically create a number of elements to match the the size of that array. (I had forgotten that setting was there - it's at the bottom of the page).

Bob
awgcas 23 Mar, 2017
Hi Bob,
I had tried already that setting, I had forgotten to mention, sorry ... 😶

It does not work: chronoforms shows always only the first author

Alessandro
GreyHead 23 Mar, 2017
Hi Alessandro,

Hmmm . . .by all means PM me the site URL, the form name, and a SuperAdmin login and I'll take a quick look.

Bob
GreyHead 23 Mar, 2017
Hi Alessandro,

Fixed I think, this is a ChronoForms bug. The code that counts the length of the array does not take into account that the first element may be hidden in the settings so it is setting the count too low.

I changed the code to add an empty entry to the beginning of the $form->data['author_table'] array to fool the code into adding one more multiplier set.
<?php
$temp = array();
$temp[] = ''; // << added this line
foreach ( $form->data['author_table'] as $a ) {
  $temp[$a['position']] = $a;
}
$form->data['author_table'] = $temp;
?>

Bob
awgcas 23 Mar, 2017
Great!!

Thank you very much Bob, now I can go forward!!

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

VPS & Email Hosting 20% discount
hostinger