mercredi 21 juin 2017

PHP checkbox post if selected some two element get no result

I have created a jquery code for my checkbox. My jquery codes working like this. If user checked some two checkboxes then I give alert like alert("You can not select this two checkbox");

$("body").on("click", ".submit", function(){


      var lookChecked = $('#c').is(':checked');
      var lookCheckedTwo = $("#java").is(':checked'); 
      var lookCheckedTree = $("#php").is(':checked');
      var lookCheckedFour = $("#html").is(":checked");
      var lookCheckedFive = $("#unix").is(":checked");

      if(lookChecked && lookCheckedTwo || lookChecked && lookCheckedTree) {
         alert("You can not select #c and #java or #c and #php at the same time");
      }



   });

This is working fine. But I want to check it also with PHP

if(isset($_POST['submit'])){
if(!empty($_POST['check_list'])) {
// Seçimlerin toplamını kontrol et

$checked_count = count($_POST['check_list']);
if($checked_count >=3) {
   echo "You can not select ".$checked_count." ";
}else{
    echo "".$checked_count." checkbox result for: <br/>";

foreach($_POST['check_list'] as $selected) {

echo "<p>".$selected ."</p>";

}


}
}

else{
echo "<b>Please select a checkbox</b>";

}

}

HTML

<form action="index.php" method="post">
<label class="heading">Select your categories:</label>
<input type="checkbox" name="check_list[]" id="c" value="C/C++"><label>C/C++</label>
<input type="checkbox" name="check_list[]" id="java" value="Java"><label>Java</label>
<input type="checkbox" name="check_list[]" id="php" value="PHP"><label>PHP</label>
<input type="checkbox" name="check_list[]" id="html" value="HTML/CSS"><label>HTML/CSS</label>
<input type="checkbox" name="check_list[]" id="unix" value="UNIX/LINUX"><label>UNIX/LINUX</label>
<input type="submit" class="submit" name="submit" Value="Submit"/>
<!----- Including PHP Script ----->
<?php include 'checkbox_value.php';?>
</form>

So what I want to do with PHP. If the user checked C/C++ and Java same time. I want to show a just warning. (No result for C/C++ and Java please select another category) or if the user selected PHP and Unix (No result for PHP and Unix please select another category). How can I do that with PHP




Aucun commentaire:

Enregistrer un commentaire