This is part of the Semicolon&Sons Code Diary - consisting of lessons learned on the job. You're in the web-development category.
Last Updated: 2024-11-21
When I went to edit an existing tax advisor via a form, the admin's email was showing in the form instead of that tax advisor's email. The advisor already had an email field set to "advisor@example.com" yet "adminuser@example.com" was showing.
The code for the form was as follows:
<?
{{ Form::model($advisor, ["url" => $url, "class" => "step_1_form"]) }}
{{ Form::text('email', $current_user->email) }}
...
{{ Form::close() }}
Here is my misunderstanding: I expected the second parameter of Form::text()
to only apply if there was no advisor email was present. But this wasn't how it
worked. The second parameter overrode anything that already existed in the DB.
Referring to the htmlcollective docs (my form library), the precedence is:
i.e. My mental model was inaccurate and I made too many assumptions based on my experience with other web frameworks like Rails.
Be sure to understand the precedence of defaults in form data and test them. In particular, the following cases need to be considered: