ChronoEngine.com homepage

Forums

Please write a review for the extension you are using on the Joomla extensions directory before posting a new question as we are being spammed by many negative reviews.

Thank you for your support!

CF6 How to load db records into input, textarea, file fields

xoles 12 May, 2017
Hello! I'm not frequent to CF but I found v6 to be absolutely awesome! Though, I can't load records into a form for the user to modify their past saved inputs.

I've tried with DB Read, with php functions and {var:function_name} inside the Value Field, but fields won't load. I can't find a clear answer for this neither on FAQs or Forum. I'm sure this should be very easy and I don't need CC, but just can't figure out how.

Documentation for CF5 recommends to add custom code on the "conditions box", but this box is not literally present inside DB Read. I used this code
<?php return array('nombre_organizacion' => $form->data['nombre_organizacion']);  ?>
inside the "fields to retrieve" box; the debugger shows a correct call for the data, but then I don't know how to load that data into the input field.

Is there an straightforward post or FAQ for this?
Max_admin 12 May, 2017
Answer
1 Likes
Hi xoles,

If there is a correct array of data then it can be set as the form "data provider" under the "display section" action.

a correct array should match the form fields names, so if your form fields names do not have a model name then you can get the correct array from a "read data" with "select type" set to "get first record", and place this in the "data provider" of the "display section":
{var:read_data_name.Modelname}

Best regards,
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
xoles 12 May, 2017
1 Likes
Thanks for the prompt reply! It works like a charm!
xoles 13 May, 2017
Now I'm trying to load the filename and call an img src, but can't get the filename to render on a custom html.

I've tried with
{filename}, {Model.filename}, {data:Model.filename}, {var:Model.filename}
and even with
$form->data["Model"]["file_name"];

Please check my debugger, where the array is being read from db correctly:
[var] => Array
                (
                    [Recursos] => Array
                        (
                            [id_recurso] => 4
                            [user_id] => 352
                            [created] => 2017-05-13 01:22:57
                            [modified] => 2017-05-13 01:23:15
                            [estructura_organizacional] => 20170512230559_xyz-png.png
                            [nomina] => 8
                            [voluntarios] => 5
                            [honorarios] => 6
                        )

                )
Max_admin 13 May, 2017
Hi zoles,

What is the name of the "read data" action used to read this record ?

The syntax should be then:
{var:read_data_name.Recursos.estructura_organizacional}

Best regards,
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
xoles 14 May, 2017
Thanks for the heads up! It works. Now, I'm struggling to keep the file record unmodified when the file field is empty... trying with no luck this two options inside a custom code box after upload and before save DB:

<?php
if(!empty($form->data["estructura_organizacional"]))
{$form->data['estructura_organizacional'] = $form->files['filename'];}
else
{unset($form->data['estructura_organizacional']);}

 if ( $form->data['estructura_organizacional'] = "undefined") {
    unset($form->data['estructura_organizacional']);
  }
?>

Record is modified with "undefined".

I also tried disabling the file field and only activating it with a previous "want to re-upload" checkbox. But no luck either.
Max_admin 16 May, 2017
1 Likes
Hi xoles,

You will need to clear the file field before the "save data" action, please try this code in a PHP action:
if(empty($this->data("field_name"))){
unset($this->data["field_name"]);
}

Best regards,
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
xoles 16 May, 2017
Hi, thanks for the help, but the record is still being updated as "undefined". Find attached image of boxes order and here the debugger output:

Array
(
    [chronoform] => modificar-recursos
    [event] => submit
    [tvout] => view
    [display-section1] => Array
        (
            [counter] => 1
        )

    [_counter] => 1
    [checkbox14] => 1
    [nomina] => 5
    [voluntarios] => 1
    [honorarios] => 2
    [estructura_organizacional] => undefined
    [modificar-recursos] => 
)

Array
(
    [validate_fields2] => Array
        (
            [log] => Automatic validation enabled.
            [var] => 1
        )

    [upload7] => Array
        (
            [path] => /home/devel/public_html/fx2/components/com_chronoforms6/chronoforms/uploads/
            [estructura_organizacional] => Array
                (
                    [extensions] => Array
                        (
                            [0] => jpg
                            [1] => png
                            [2] => gif
                            [3] => pdf
                            [4] => doc
                            [5] => docx
                            [6] => txt
                            [7] => zip
                        )

                    [info] => File is not present.
                )

            [var] => Array
                (
                )

        )

)
Max_admin 16 May, 2017
Hi xoles,

Where does the "undefined" word come from in your code ?

Does this form use AJAX ?

Best regards,
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
xoles 16 May, 2017
Yes, that was it. Disabling AJAX was the solution.
jelle 05 Jan, 2018
I have also a field, but when i'm using the code below it's updating the field with and empty value.

if(empty($this->data("Fotovoorkant"))){
unset($this->data["Fotovoorkant"]);
}
Max_admin 15 Jan, 2018
Hi Jelle,

I understand that you could solve this later, correct ?
$new_data = $this->data;
if(empty($this->data["Fotovoorkant"])){
unset($new_data["Fotovoorkant"]);
}
$this->set("new", $new_data);//use {var:new} as the data provider now

Best regards
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
jelle 16 Jan, 2018
1 Likes
Yes, this is already solved
This topic is locked and no more replies can be posted.

2Checkout.com

2CheckOut.com Inc. (Ohio, USA) is an authorized retailer for goods and services provided by ChronoEngine.com