mardi 30 janvier 2018

Laravel if checkbox value true, price is required

i have an checkbox in my blade where users can enable an other Payment method and now i want if someone check this box, the price is required for this Payment method.

Checkbox blade:

<div class="form-group">

        <label for="accept1"><font color="#b7b7b7"><img src="/img/accept1.png" height="20" width="20"> Accept other payment method</label>

       <input type="checkbox" value="true" name="accept1"> Yes</font>

        <hr>
</font>
      </div>

Price blade:

<div class="form-group">

        <label for="newprice"><font color="#b7b7b7"><img src="/img/newprice.png" height="20" width="20"> New Price:</font></label> 

        <input type="number" step="any" name="newprice" id="newprice" class="form" value="" >

Controller:

    if ($request->accept1== 'true') {
            $product->accept1= true;
          }


      if ($request->newprice== 'true') {
        if (!is_numeric($request->newprice) || $request->newprice<= 0.0001) {
          session()->flash('errormessage',' Price is required');
          return redirect()->back()->withInput();
        }
}

If someone click the checkbox now , he must also enter an Price or he get error Message.

How can i do this or change the code?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire