简体   繁体   中英

Laravel passing 0 as value through form and getting null

So I have a simple form with select input which has an option with value of "0" :

<form method="post" action="{{ action('Something@something') }}">
    <select name="status">
           <option selected value="0">Bla bla bla</option>
    </select>
    <button type="submit">Press me</button>
</form>

Error occurs, when I select the only option from select input and in controller I get null instead of "0" number (I did check with dd() method). Is it possible that this number gets lost in an integrated middleware or somewhere else? Or is this a PHP trick?

Okay, the answer was that in my Middleware I had this code :

public function handle($request, Closure $next)
{
    if (!Auth::check()) {
        return redirect('/blablabla');
    }

    foreach ($request->input() as $key => $value) {
        if (empty($value)) {
            $request->request->set($key, "");
        }
    }

    return $next($request);
}

problem was with empty($value) . I changed empty() to !isset() and everything fixed

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM