PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, February 22, 2022

[FIXED] How can I pass an array of hidden informations in a POST request in Cake 3.2?

 February 22, 2022     arrays, cakephp, cakephp-3.0, php, post     No comments   

Issue

I have created a form for a POST request, but I need to send an array of information that must be not visible in that form. The array consist in a not specified number of other arrays.

My array is called "$dati" and is made by a not bounded number of arrays with three information each.

The code of my form is:

<?= $this->Form->create(null,['type'=> 'post', 'url'=>['action'=>'selectForSell2',$rassegnaselezionata->id,$showselezionato->id,$proiezioneselezionata->id  ]]) ?>
    <?= $this->Form->input('stato', ['options' => ['tutti' => 'Tutti i Soci',  'firmato' => 'Soci Firmati', 'approvato' => 'Soci Approvati'] ] ); ?>
    <?= $this->Form->input('campo', ['options' => ['cognome' => 'Cognome', 'nome' => 'Nome', 'codicefiscale' => 'Codice Fiscale'] ] ); ?>
    <?= $this->Form->input('ricerca', ['label' => false, "class" => " form-control input-medium", "placeholder" => __('Ricerca'), 'visible'=>false]); ?>
    <?= $this->Form->button(__('Submit')) ?>
<?= $this->Form->end() ?>

Solution

In my projects, I have the following element as hidden.ctp:

if (isset($model)) {
    $model .= '.';
} else {
    $model = '';
}

foreach ($fields as $field => $values) {
    if (is_array($values)) {
        echo $this->element('hidden', ['model' => $model . $field, 'fields' => $values]);
    } else {
        echo $this->Form->hidden($model . $field, ['value' => $values]);
    }
}

Then you can just call it with

echo $this->element('hidden', ['fields' => $dati]);


Answered By - Greg Schmidt
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing