How to get value from the field from custom php code

Retrieve a custom field value in CF PHP code.

Overview

The issue occurs when using incorrect methods to access form field data.
Use the data method with the field name to get the current value, ensuring the field is properly set in the form submission.

Answered
ChronoForms v6
se serguei_kp 29 Dec, 2020
Hello, I'm trying to get value of a field 'checkbox104' from custom php code:

$check_box_get = $this->get('checkbox104', 0);
$check_box_data = $this->data('checkbox104', 0);

if ($check_box_data != 1) {
echo $check_box_get;
echo $check_box_data;
$this->data('checkbox104', 1, true);
return $article_note;}
else {
echo $check_box_get;
echo $check_box_data;
return 0;}

but it always returns default value with $this->get or with $this->data.

Array
(
    [Itemid] => 1176
    [option] => com_content
    [view] => article
    [id] => 232
    [lang] => en
    [catid] => 2
    [_ga] => GA1.2.108603241.1608997853
    [fcba6eff3bcff11268aeb9d73ebac6b2] => b411edc9d98f579395e2c42ed9946e63
    [6fc35e6b52a32ae9a673b76d96b4731e] => 945075db290ed8e824ec8c16dc2371be
    [joomsef_lang] => en
    [_gid] => GA1.2.1966733552.1609255125
    [language] => en-GB
    [_gat] => 1
    [checkbox104] => 1
)
Array
(
    [set_checkbox] => Array
        (
            [returned] => 
            [var] => 
        )

    [default_service_type_php] => Array
        (
            [returned] => transfer_indi
            [var] => transfer_indi
        )

    [default_service_name_php] => Array
        (
            [returned] => request-form-all-services
            [var] => request-form-all-services
        )

    [check_box] => Array
        (
            [returned] => 
            [var] => 
        )

)
he healyhatman 30 Dec, 2020
Answer
$this->data('fieldname', 'optional_default_value_here') is for form data, get is for {var}s
This topic is locked and no more replies can be posted.