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

Form Phalcon

I have 2 steps for registration. In second step i want to keep all fields and values in hidden fields..and im using same form file for both. In my controler

 $form    = new RegisterForm(null, array("makehidden" => true);

in RegisterForm.php

if ($options['makehidden']) {
    $field_type =  "Hidden";
} else {
    $field_type =  "Text";
}

$uname =  new $field_type("uname");

but I'm getting error............ how to solve this?



98.9k
Accepted
answer

You have to use the classname plus its namespace:

if ($options['makehidden']) {
    $field_type =  'Phalcon\Forms\Element\Hidden';
} else {
    $field_type =  'Phalcon\Forms\Element\Text';
}

$uname =  new $field_type("uname");

https://php.net/manual/en/language.namespaces.importing.php