Send Number Using HTML Form to Laravel

给你一囗甜甜゛ 提交于 2020-01-16 05:26:33

问题


I am curious on how laravel validates number, i had this code:

$valid = \Validator::make(['lat' => '2.3711025426955', 'lng' => '99.0805054179688'], [
            'lat'  => 'required_with:lng|digits_between:1,15',
            'lng' => 'required_with:lat|digits_between:1,15',
          ]);
          dd($valid->fails());

which is invalid, it will work if we had the numbers without quotation marks. However, whatever input type of the input field to pass lat and long through html form. It regarded as string therefore invalid. I tried to dd($request->all() and the output are like:

array:2[
        "lat" => "2.3711025426955"
        "lng" => "99.0805054179688"
]

I pass it using forms like:

    <input type="text" name="lat">
    <input type="number" name="lat">

Both aren't working, it's rather bother some that i only works on backend but realize this problem messing around. I am using Laravel 5.1.26 anyway, hope someone shed some light on this - previously i'm pretty certain it works even with quotation marks. Not sure, what's wrong but, laravel uses php function is_numeric but somehow did not recognize my input (with quotation marks) as number.

Edit to clarify, i got this error: The lat must be between 1 and 15 digits. which is kind of weird, i'd say. To the weirdness is_numeric('2.3711025426955') is actually recognize my numbers correctly. Now i'm much more.. confused.

来源:https://stackoverflow.com/questions/34087356/send-number-using-html-form-to-laravel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!