unlockField -> could not be converted to string

Hello community member, this is my first time using your brain.

I am trying to migrate CakePHP 3.6 to 4.4.

I have inputs with checkboxes.

<?php foreach($produits as $produit): ?>
   <div class="custom-control custom-checkbox custom-control-inline">
      <input type="checkbox" class="custom-control-input" id="produit-<?= $produit->id_auto ?>" 
         name="jct_user_prod[][nom_produit]" value="<?= $produit->nom ?>"
         <?= empty($utilisateur->jct_user_prod) && $produit->nom === 'Expert' ? 'checked' : '' ?>
         <?= !empty($utilisateur->jct_user_prod) && in_array($produit->nom, $this->Utils->hashExtract($utilisateur->jct_user_prod, 'nom_produit')) ? 'checked' : '' ?>>
      <label class="custom-control-label" for="produit-<?= $produit->id_auto ?>"><?= $produit->nom ?></label>
</div>
<?php endforeach; ?>

And using a unlockField from Form Helper :

<?= $this->Form->unlockField('jct_user_prod'); ?>

I got this error :

Object of class Cake\View\Helper\FormHelper could not be converted to string

If I just remove the ‘unlockField’ from the view, the view will appear but cannot POST it.

Has anyone encountered this kind of problem before? I would like to pass exclusively via the helper but making sure to have checked which results from a different entity will cause problems.

FormHelper::unlockField() has a return value, $this, so don’t echo it, ie don’t use the short echo tag <?=, but the regular php tag <?php.

https://www.php.net/manual/en/language.basic-syntax.phptags.php

1 Like

Hello @ndm,

Thank you for your answer, the problem solving is exactly that.

Thank you for your help.