if php based on select form

Asked

Viewed 24 times

1

I am trying to create a form with payment mode (A view/Installments) and wanted a new field available only if the option Installments is selected, but without having to price

<div class="form-group col-md-4">      
    <label for="campo3">Parcelas</label>    
    <select class="form-control" name="customer['parcelas']">
        <option value = "0" selected>A vista</option>
        <option value = "10">Parcelado</option>
        
        </select>
    </div>
    <?php if($customer['parcelas']>0){ echo 
                "<div class='form-group col-md-4'>     
    <label for='campo3'>Parcelas</label>    
    <select class='form-control' name='customer['parcelas']'>
        <option value = '0' selected>A vista</option>
        <option value = '10'>Parcelado</option>
        
        </select>
    </div>";} ?>
  • ignore the fact that the code repeats itself, just wanted to demonstrate an echo in html before working on the second form

  • do not forget to convert it to int (intval), and before that also check if it is a valid value for such a conversion (is_numeric), to be able to compare it as a number

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.