Home>

On a registration screen, the checked radio button is saved in the database, and the next time it is displayed, the same radio button as before will be checked.

As a flow, the value obtained from the database is stored in $sex using query builder in php file.
I'm trying to switch it to display with Phalcon<.volt file> ;, but it doesn't work.
Please give me some advice.

※ By default, I want to have "Man" checked.

Phalcon code

&lt;? php
if (($sex === no) || ($sex === "")) {
    $checked0 = "checked";
    $checked1 = "";
} else {
    $checked0 = "";
    $checked1 = "checked";
echo&lt;&lt;&lt;EOT
&lt;html&gt;&lt;body&gt;
&lt;input type = "radio" name = "sex" value = 0 $checked0 /&gt;
&lt;input type = "radio" name = "sex" value = 1 $checked1 /&gt;woman
&lt;/body&gt;&lt;/html&gt;
EOT;
?&gt;
  • Answer # 1

    I don't know how to retrieve data from DB
    Processing when GET is done for the time being

    <? php
    $checked ["sex"] = ["0" =>"", "1" =>""];
    $sex = filter_input (INPUT_GET, "sex");
    $checked ["sex"] [$sex] = "checked";
    echo<<<EOT
    <form>
    <label><input type = "radio" name = "sex" value = "0" {$checked ["sex"] ["0"]}>male</label>
    <label><input type = "radio" name = "sex" value = "1" {$checked ["sex"] ["1"]}>Female</label>
    <input type = "submit" value = "go">
    </form>
    EOT;
    ?>