This is one of those tips I hesitate to even share. Is it too basic or obvious?
Well I bumped into it briefly, so I'm going to assume someone out there will benefit from the reminder as well.
When you have a default option in a select list, like "Select One", the intention is that the user picks a value before submitting.
But if you just specify it as <option>Select one</option>
without a value
attribute, then the form sends the option text "Select one" as the field value.
This is not what you want, and it's especially problematic if it's a required field.
HTML form validation and Laravel's validation rules will not catch that field in this case.
Even worse, you can write a nice feature test that will pass as expected, even though the real form will have a bug.
By adding value=""
to that default option, the browser now submits an empty string until the user chooses something real, and validation works as intended.
Here to help,
Joel
P.S. As this tip proves, it's easy to overlook something obvious at times. If you're stuck and want a second set of eyes, I can help you get unstuck.