I have a register form where users can sign up and I recently added two radio buttons to define users type.
Đang xem: Nhận dữ liệu form từ radio button
Example:
(*) I want to buy (*) I want to sellHere”s how I was thinking to do this: I added a boolean field in the users table and I was thinking to check if I want to buy is checked then I store 1 in the database if the other one is checked then I store 0.
The thing is, I”m not sure how to check in the controller if the radio button is selected or not.. I tried to look in the documentation and on google but all I found were some ideas using the Form facade which as I know is no longer used in 5.4…
Remeber: Checkbox and radio button sends values on server end, if and only if they are marked as checked, if not checked that, then no values will be sent out to controller end. so you can do this check in your controller
eg:
public function myMethod(Request $request){ //2nd parameter means, if radio is not selected then use default value $radio = $request->get(“radion_button”, 0);}
HTML
{{ Form::radio(“result”, “buy” , true) }} {{ Form::radio(“result”, “sell” , false) }}Without Form Facade
Controller
$fields = Input::get(“result”); if($fields == “buy”){ // logic } else{ // logic }
Thanks for contributing an answer to Stack Overflow!
Please be sure to answer the question. Provide details and share your research!
But avoid …
Asking for help, clarification, or responding to other answers.Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Post Your Answer Discard
By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy
Not the answer you're looking for? Browse other questions tagged php laravel laravel-5.3 laravel-5.4 or ask your own question.
site design / logo © 2021 Stack Exchange Inc; user contributions licensed under cc by-sa. rev2021.3.3.38704