Forums

Cloned fields and array editing/reading

mcevoli 15 Mar, 2011
Hello!
I have a simple form with a field and a button to add other identical fields.
All input fields are stored in one array (<input type="text" name="email[]">).
My problem is:

-when i access to the table from chronoconnectivity I would like to access to any single array element; now I have an {email} tag in my chronoconnectivity body but, of course, it prints out something like "myemail1, myemail2, myemail3" etc.

-if I click edit_record button, my email fields are not filled with database data.

Thank you for you help!
GreyHead 15 Mar, 2011
Hi mcevoli,

You can unpack the values using PHP in the body box
<?php
$email = explode(', ', $MyRow->email);
?>
This will put the current values into the $email array (check if the divider is just comma or comma+space).

Bob
mcevoli 15 Mar, 2011
Thank you!
My problem is how to print one entry for each body "loop":

<tr><td>{name_ric}</td><td>{surname_ric}</td><td>{data}</td><td>{communication}</td></tr><tr><td></td><td></td><td></td><td></td><td>{name_own}</td><td>{surname_pro}</td><td>{address}</td><td>

<?php
$email = $MyRow->email;
$pieces = explode(", ", $email);
for($i = 0; $i < count($pieces); $i++){
echo $pieces[$i]; // piece
}

?>

</td><td>{edit_record}</td><td>


I would like to print in my first row $pieces[0], in my second one $pieces[1] and so on.
In the way I coded of course doesn't work because each time it execute the entire cicle, printing all the content.

Thanks!
GreyHead 15 Mar, 2011
Hi mcevoli ,

Hmmm . . . the best answer is not to save your data like that :-)

This should work: header box
<?php
global $i;
$i = 0;
?>


Body box
<?php
global $i;
$email = $MyRow->email;
$pieces = explode(", ", $email);
echo $pieces[$i]; // piece
$i++;
}
?>


Bob
mcevoli 16 Mar, 2011
Thank you Bob! I'll buy you surely a beer.

Now My form display as I wished, but I have another issue:

When I click on frontend edit_records (but also from Admin backend), the array fields are not filled with data.

Thanks!
GreyHead 16 Mar, 2011
Hi mcevoli,

Usually the data isn't filled if the database table doesn't have a primary key set so ChronoForms can't identify which record to use. Could that be the problem here?

Bob
mcevoli 16 Mar, 2011

Hi mcevoli,

Usually the data isn't filled if the database table doesn't have a primary key set so ChronoForms can't identify which record to use. Could that be the problem here?

Bob



Standard input fields, for example this one
<input class="cf_inputbox required" maxlength="150" size="30" title="" id="text_2" name="nome_ric" type="text" />

are filled correctly.

My problem is with fields like this:
<input class="cf_inputbox" maxlength="150" size="20" title="" id="text_8" name="nome_pro[]" type="text" />


where the name attribute is an array.
GreyHead 16 Mar, 2011
Hi mcevoli,

Ah OK. I suspect that the code just isn't clever enough to interpret array results. :-(

Though - I've just taken a look at the code and it ought to be OK (ChronoConenctivity loads the form with the Profile Plug-in enabled to do the substitution). It would take a lot more digging to work out exactly what is happening.

I rarely use the {edit_record} links -- I prefer to link to a form directly. That way I have complete control on what is displayed and how the results are handled.

Bob
francosdad 28 Sep, 2011

Hi mcevoli,

You can unpack the values using PHP in the body box

<?php
$email = explode(', ', $MyRow->email);
?>
This will put the current values into the $email array (check if the divider is just comma or comma+space).

Bob




A little suggestion,

I would recommend showing the information that {variable} in html is euqal to $MyRow->variable somewhere in tutorial section or something. I searched hours to find it again.

I knew there had to be a solution to access the results inside php code, but could not remember.
This is very useful if somebody for example "connects" several forms and results in one list.
GreyHead 28 Sep, 2011
Hi jackprince,

I agree.

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