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

trick : re-populate forms if submission fail..

nothing complex.. you need J-query and this populate pluggin: https://github.com/dtuite/jquery.populate

in your controller save action, save forms datas into session (before redirect):


        $this->session->set('currentForm', $_POST);

in your volt file, add:

    <script>
        var formDatas = {};
    </script>
    {% if session.get('currentForm') !== null %}
        <script>
            formDatas = {{ session.get('currentForm')|json_encode }};
        </script>
    {% endif %}
    <?php unset($_SESSION['currentForm']); ?>  //not found how to do that with volt languages...

then in your js file:

    if (formDatas !== undefined  &&  formDatas !==  "")  {
        $("#your-form").populate(formDatas, {resetForm:true});
    }

that all folkz.. don't forget to remove password from $_POST if any, or they will be displayed clear in the htm source..

Why would you need plugin for that?

With raw PHP you can populate form data after submit..



11.6k

html code more readable, at least, and fast to add on existing code..

edited May '16

<?php unset($_SESSION['currentForm']); ?> = {{ session.remove("currentForm") }}

I think is better using: {{ text_field("something") }}

It automatically repopulates XD



11.6k

I use {{ form.render('item', ['class': 'form-control', 'required': 'required']) }}, with form designed in form folder, but it does repopulate itself when you submit a form that rejected (there is a redirection in case of failing)..

thank for the volt hint...