Populate the text field when the form first load does not work [Chronoforms v6.1.4]

serguei_kp 27 Dec, 2020
Hello, in chronoforms 6.1.4,
I'm trying to use Custom code to populate the existing text field 'article_title' when the form is loaded first time, but it does not work.
Custom code is in: load > Actions.
Instead the code below creates second field with same name and populates it with the value.
But I need to set the default value of the selection field depending on the value of 'article_title' field, but it does not work this way.

<?php
$article_title = '';
$id = JRequest::getInt('id');
$article =& JTable::getInstance('content');
$article->load($id);
$article_title = $article->get('note');
$form->data['article_title'] = $article->get('title');
?>
<input name="article_title" id="article_title" value="<?php echo $article_title; ?>" />

I also try </>PHP code, I see in the debug that var contains correct value, but I don't know how to put this value into 'article_title' text field:
Array
(
    [Itemid] => 1176
    [option] => com_content
    [view] => article
    [id] => 232
    [lang] => en
    [catid] => 2
    [fcba6eff3bcff11268aeb9d73ebac6b2] => 916d0d116b8a7881f337f43434468f14
    [joomsef_lang] => en
    [_ga] => GA1.2.552819003.1609076173
    [_gid] => GA1.2.689536733.1609076173
    [language] => en-GB
    [_gat] => 1
)
Array
(
    [php4] => Array
        (
            [returned] => stdClass Object
                (
                    [data] => Array
                        (
                            [article_title] => request_form_all_services
                        )

                )

            [var] => stdClass Object
                (
                    [data] => Array
                        (
                            [article_title] => request_form_all_services
                        )

                )

        )

)
Populate the text field when the form first load does not work [Chronoforms v6.1.4] image 1

Populate the text field when the form first load does not work [Chronoforms v6.1.4] image 2

Best regards.
serguei_kp 27 Dec, 2020
Answer
I found the solution:
Just add : {var:default_service_name_php} or {var:default_service_type_php}
in the field Value of each feild where you need to load default value.

PHP code:
Name: default_service_name_php
$article_title = '';
$id = JRequest::getInt('id');
$article =& JTable::getInstance('content');
$article->load($id);
$article_alias = $article->get('alias');
return $article_alias;

PHP code:
Name: default_service_type_php
$article_title = '';
$id = JRequest::getInt('id');
$article =& JTable::getInstance('content');
$article->load($id);
$article_note= $article->get('note');
return $article_note;
You need to login to be able to post a reply.