We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Show the first element of a select value received by post

Show the first element of a select value received by post

In my controller

public function editAction($CONT_CODIGO) {
    if (!$this->request->isPost()) {
        $spm_contacto = SpmContacto::findFirstByCONT_CODIGO($CONT_CODIGO);
        if (!$spm_contacto) {
            $this->flash->error("spm_contacto was not found");

            return $this->dispatcher->forward(array(
                        "controller" => "spm_contacto",
                        "action" => "index"
            ));
        }
        $this->view->CONT_CODIGO = $spm_contacto->CONT_CODIGO;

        $this->tag->setDefault("CONT_CODIGO", $spm_contacto->CONT_CODIGO);
        $this->tag->setDefault("CONT_CEDULA", $spm_contacto->CONT_CEDULA);
        $this->tag->setDefault("CONT_RUCIDE", $spm_contacto->CONT_RUCIDE);
        $this->tag->setDefault("CONT_NOMBRE", $spm_contacto->CONT_NOMBRE);
        $this->tag->setDefault("CON_ESTADO", $spm_contacto->CON_ESTADO);
        $this->tag->setDefault("CONT_TELEFO", $spm_contacto->CONT_TELEFO);
        $this->tag->setDefault("CONT_DIRECC", $spm_contacto->CONT_DIRECC);
        $this->tag->setDefault("CONT_AREA", $spm_contacto->CONT_AREA);
        $this->tag->setDefault("CONT_CARGO", $spm_contacto->CONT_CARGO);
        $this->tag->setDefault("CONT_TIPOXX", $spm_contacto->CONT_TIPOXX);
        $this->tag->setDefault("CONT_EMAIL", $spm_contacto->CONT_EMAIL);
        $this->tag->setDefault("CONT_USUARIO", $spm_contacto->CONT_USUARIO);
        $this->tag->setDefault("CONT_CLAVE", $spm_contacto->CONT_CLAVE);
        $this->tag->setDefault("CONT_CLAVEE", $spm_contacto->CONT_CLAVEE);
    }
}

in my view

<?php echo $this->tag->textField(array("CONT_AREA", "size" => 30, "class" => "form-control", "id" => "fieldContArea")) ?>

And the item I received by post will replace the text field for select shows as well

         <?php
echo Phalcon\Tag::select(array(
"CONT_CARGO", SpmReferencia::find("REFE_CODIGO='00'"),
"using" => array("REFE_CODIGO", "REFE_DESCRI")
    ,'useEmpty'   => true,
    'id'  => 'fieldContCargo',
    'emptyText'  => 'Escoge uno...',
    'emptyValue' => ''
));
?>

and that the first element is the value received by post



43.9k

Hi,

I do not exactly understand what you are trying to achieve ...



81.2k

when editing I want to display the first stored item in the database, and the rest which are brought by the select



43.9k

Hi,

when editing I want to display the first stored item in the database

that looks ok in your code, you're accessing the edit action through a GET request and you use

$spm_contacto = SpmContacto::findFirstByCONT_CODIGO($CONT_CODIGO);

and then set the tags defaults .... this is in my opinion all good.

Now, when using POST request to the same editAction (for update I suppose), you're missing all the logic in your controller action.