Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

panthro's avatar

Null or empty strings for form defintiions?

The inertia examples show form inputs a empty strings:

const form = useForm({
    name: '',
    ....

Laravel starter kits user null:

const form = useForm({
    name: null,
    ....

When data is not defined in my backend, for optional fields null is returned. So, I when populating a form in edit mode, if I use this data directly it will have a null value.

What is best practice here when defining vars in inertia/vue? Null or empty strings?

0 likes
1 reply
tykus's avatar
tykus
Best Answer
Level 104

In general HTML, an empty form input is an empty string; Laravel then trims and normalizes inbound Request payloads.

So use either, just be consistent within your own codebase.

1 like

Please or to participate in this conversation.