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

Set a option in form and entities when we edit it

Hello all

//PostForms.php
$price = new Text(
    'price',
    ['
        class' => 'form-control',
        'value' => 12
    ]
);

//PostsController
public function editAction($id)
{
$id = (int) $id;
if (!$object = Posts::findFirstById($id)) {
    $this->flashSession->error(t('Posts doesn\'t exist.'));

    return $this->currentRedirect();
}
$form   = new PostsForm($object);
$this->view->setVars([
    'form' =>  $form,
    'object' => $object
]);

$this->assets
    ->addJs('backend/js/plugins/staps/jquery.steps.min.js')
    ->addJs('backend/js/plugins/validate/jquery.validate.min.js')
    ->addJs('backend/js/plugins/iCheck/icheck.min.js')
;
$this->assets
    ->addCss('backend/css/plugins/steps/jquery.steps.css')
    ->addCss('backend/css/plugins/iCheck/custom.css')
;
return $this->view->pick($this->router->getControllerName() . '/new');
}

/new.volt

{{ form.render('price')}} //<input type="text" class="form-control" value="0.00" name="price" id="price">

{{ form.render('price', ['value' : 12])}} //same result like above

So I want to overwrite it like

<input type="text" class="form-control" value="12" name="price" id="price">

How to do that?



12.2k

in PostsConyroller:


$this->tag->setDefault('price', 12);


58.4k

Hello

It not working :)