jeudi 22 décembre 2016

Check if all dynamic radio buttons are checked before submit

i am not much sure how can i check if all my dynamic radio button that came from DB are checked before i submit my form. I am working on a Booking Project, and the clue is about food package and subpackage. Based on the package the client choose, than he will check like a radio button which dish does he want before submitting and going to booking view. If not all the product are selected (1 for each category) the form can not be submit.My view:

 {!! Form::open(array('route' => ['continue_pacakage_booking',$sub_package->id],'id' => 'form','class'=>'form-horizontal','novalidate' => 'novalidate','role' => 'form', 'enctype' => 'multipart/form-data', 'onsubmit' => "validateForm()")) !!}
@foreach($dishes_and_categories as $key=>$dishes_and_category)
    <section style="padding: 70px 50px">
        <div class="container"style="border-bottom: 10px solid #F0F0F0" >
            <div class="row">
                <!-- section title -->
                <div class="col-md-12 text-center">
                    <span class="title-small text-uppercase letter-spacing-3 font-weight-600" style=" color: #da7e57;"></span>
                    <div class="separator-line-thick bg-black no-margin-bottom margin-one xs-margin-top-five"></div>
                </div>
                <!-- end section title -->
            </div>
            <section class="wow fadeIn blog-details-text" style="padding-top: 30px;padding-bottom: 30px">
                <div class="container">
                    @foreach($dishes_and_category['dishes'] as $dish)
                        <div class="col-md-4 col-sm-6">
                            <label>
                                <input type="radio" @if($dishes_and_category['id_category'] == 6) disabled @endif name="" value="" />
                                <img src="http://ift.tt/2h5UHvB}}" style="border-radius: 50%;height: 250px;width: 100%">
                                <p style="text-align: center; font-weight: bold" class="text-uppercase"></p>
                            </label>
                        </div>
                    @endforeach
                </div>
            </section>
        </div>
    </section>
@endforeach
<div class="col-md-12">
<button class="highlight-button btn btn-large btn-round button xs-margin-bottom-five" type="submit"  id="select_table" name="select_table" style="margin-left: 805px; width: 278px; margin-bottom: 20px">Continua Prenotare</button>

</div>
{!! Form::close() !!}

and my controller :

public function show($id)
{

    $sub_package = Sub_Packages::find($id);
    $id_package = $sub_package->id_package;

    $selected_categories = DB::select('SELECT c.id as id_category , c.name as category_name FROM sub_packages_dishes s LEFT JOIN packages_menu_categories c ON s.id_package_menu_category = c.id WHERE s.id_sub_package = '.$id.' GROUP BY s.id_package_menu_category');
    $dishes_and_categories  = array();

    foreach ($selected_categories as $selected_category)
    {
        $dishes =  DB::select('SELECT s.id AS id_pmcd , d.id , d.name ,d.image FROM `sub_packages_dishes` s LEFT JOIN `dishes` d ON s.id_dish = d.id WHERE s.id_sub_package ='.$id.' AND s.id_package_menu_category ='.$selected_category->id_category);
        $object=
            [
                'id_category' => $selected_category->id_category,
                'category_name' =>$selected_category->category_name,
                'dishes' => $dishes
            ];
        array_push($dishes_and_categories,$object);
    }
    return view('package.view_sub_package',['id_package' =>$id_package ,'sub_package' =>$sub_package,'dishes_and_categories' =>$dishes_and_categories]);

}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire