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

Adding a default value to "email_field" in volt?

Making my form as friendly as possible, I wish to repopulate it with the details entered by the user even when they got something wrong. In this case, I am using "email_field" in volt to show a a field for email entry that will use initial validation by the browser when supported (Opera/Chrome but not Safari). I then server-side check the email address is both valid and not a common disposable address. However, "email_field" and its php contemporary Phalcon::Tag::emailField do not respect passing in a "value" default, only "class". NOTE: I AM ASKING ABOUT VALUES NOT PLACEHOLDERS!

How can I achieve the equivalent of the following?:

{{ email_field("email","value":"somedefault") }}



174
Accepted
answer
edited May '15

I had the same problem, it seems this synthax is accepted by volt : {{ email_field({'email','value':"something"}) }}



764
edited May '15

That worked perfectly, many thanks.

To complete the thought for those who need it, this is the syntax for adding a default value and a class:

{{ email_field( { "email", "class" : "<someclass>", "value" : "<default value>" } ) }}



764

The plot thickens: This problem is now fixed in version 2.0.2.

You can return to

{{ email_field( "email", "class" : "<someclass>", "value" : "<default value>" ) }}

So you must take away the extra braces that were originally needed as a work around. This is much better, but it was annoying to go back and fix all my email fields!

thank topic. It's helpfull for me :)