doubt with form in HTML5 and PHP

0

I have the following form that I create with PHP:

echo '<form name="frmCalificar" method="post" action="calificar.php">';
            echo '<br>Calificacion:<input type="number" name="txtCalificacion" required/><br>';
            echo '<p>Observacion:</p><textarea name="txtObs" rows="5" cols="21" ></textarea><br>';  
            echo '<input type="submit" class="btn btn-danger" name="btnRechazar" value="Rechazar">';
            echo '<input type="submit" class="btn btn-success" name="btnAceptar" value="Aceptar">';
            echo '</form>';

It looks shows as follows:

As you can see in the code the qualification space is required at the time of submitting the form, but I only want it to be required when clicking on the accept button, when rejecting it, that field is not required, is there any way to do this? that at the time of pressing the button accept if the qualification field is blank ask me, but by clicking on reject the form can be sent without being forced to put something in qualification.

note: for the 2 buttons you must save the comment field, but without being required

    
asked by Yept 16.08.2018 в 09:05
source

1 answer

1

For your specific case you can use the formnovalidate attribute for the submit buttons that what you do is that if you click on that submit no Validate the form, but of course for more complex forms where the rejection if it may require some validation will not serve you as it cancels the validation of the whole form, in those cases, you will need if or if you do your own validation with javascript .

echo '<input type="submit" formnovalidate class="btn btn-danger" name="btnRechazar" value="Rechazar">';

Look to see if it helps and you tell me, I've done a little test in local and seemed to go well.

    
answered by 16.08.2018 / 09:22
source