Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[L4] Empty string input value treated as null / not set #344

Open
jakobjp opened this issue Jul 4, 2014 · 2 comments
Open

[L4] Empty string input value treated as null / not set #344

jakobjp opened this issue Jul 4, 2014 · 2 comments
Labels
Milestone

Comments

@jakobjp
Copy link

jakobjp commented Jul 4, 2014

I'm having some trouble using the Former plugin for Laravel, to handle forms & fields.

The use-case is an "edit"-form for a given model.

Former::text('title')
  ->label('Title')
  ->value( $title );

Former::text('description')
  ->label('Description')
  ->value( $description );

Rules:

  • The title must always exist and be at least 10 chars long.
  • The description may be empty.

Expected behaviour:

When loading the edit form, I expect the form to show the values of $title and $description in the fields.

Whenever submitting a the form with invalid field-values, I expect the submitted values to be shown in the fields, instead of the values of $title and $description.

Problem:

This works only when submitting non-empty strings!

When submitting an empty-string, it's like Former handles it like the field-hasn't even been submitted, and therefore uses the value given by $title or $description instead.

I thought Former was able to do this "smart", and take the value($variable) value only if the posted data does not contain the field. But it seems Former is taking the variables value also when the submitted was empty.

Why is this a problem?

Imagine you edit both fields, and actually want to change the title and remove the description entirely, which is valid according to the rules. Then, because you entered a too short title, the validation does not pass, and title will get the new (too short) title as field-value, while the description value will fall back to the value of the $description variable, instead of showing an empty field, which was posted.

It feels like $_POST['description'] = "" is treated like $_POST['description'] = null or is not set - even though the empty field is part of the post.

http://stackoverflow.com/questions/24575011/laravel-former-input-field-posted-with-empty-value-shows-old-original-value-in

@claar
Copy link
Member

claar commented Mar 4, 2015

I've run into this myself and thought it was odd. I agree that a POST'd value, even if empty, should override ->value().

@claar claar added the Bug label Mar 4, 2015
@claar
Copy link
Member

claar commented May 30, 2017

Unfortunately, I would consider this to be a fairly large breaking change -- let's target this for 5.0.0

@claar claar added this to the 4.2.0 milestone May 31, 2017
@claar claar modified the milestones: 4.2.0, 5.0.0 Jan 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants