0

I'm trying to submit the form below but it fails to work:

<form action="venues.php" id="filterform" method="post" name="filterform">
    <label class="custom-control custom-checkbox">
        <input class="custom-control-input" name="Alfresco" type="checkbox">
        <span class="custom-control-indicator"></span>
        <span class="custom-control-description">Alfresco</span>
    </label>
    <label class="custom-control custom-checkbox">
        <input class="custom-control-input" name="WaterFront" type="checkbox">
        <span class="custom-control-indicator"></span>
        <span class="custom-control-description">WaterFront</span>
    </label>
    <label class="custom-control custom-checkbox">
        <input class="custom-control-input" name="Nature" type="checkbox">
        <span class="custom-control-indicator"></span>
        <span class="custom-control-description">Nature</span>
    </label>
    <label class="custom-control custom-checkbox">
        <input class="custom-control-input" name="Classy" type="checkbox">
        <span class="custom-control-indicator"></span>
        <span class="custom-control-description">Classy</span>
    </label>
</form>

Below is the PHP code I use to handle the form submission:

if ( isset( $_POST["Alfresco"] ) ) {
    $query = 'SELECT venue_name, picture, price, capacity
        FROM venues
        WHERE theme = "Alfresco"
        LIMIT ' . $start_from . ' , ' . $items_page . ' ; ';
    $result = $con->query( $query );
    $num_results = $result->num_rows;
    // etc.
}

What am I doing wrong and how can I make it work?

I seem to have a problem with check boxes as other input fields with text as type works well.

I have the submit button.

       <div class="modal-footer">
    <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
    <button type="submit" class="btn btn-primary" name="submitForm" form="filterform" value="submitForm" id="submitForm">Filter</button>
  </div> 
</form>
alexvin
  • 41
  • 7
  • Try using empty() instead of isset – Frosty Jan 20 '18 at 15:54
  • @Innervisions no, `isset()` is what's required for checkboxes. – Funk Forty Niner Jan 20 '18 at 15:55
  • Asking the obvious question first; is the checkbox checked upon submitting the form? – Qirel Jan 20 '18 at 15:57
  • Possible duplicate of [How to read if a checkbox is checked in PHP?](https://stackoverflow.com/questions/4554758/how-to-read-if-a-checkbox-is-checked-in-php) – garrettlynchirl Jan 20 '18 at 16:02
  • @alex what are you trying to do here? Did you in fact check the checkbox in question? Plus, there isn't a value for it, so that to me is the most likely issue here. – Funk Forty Niner Jan 20 '18 at 16:04
  • 1
    Where is your submit button, to submit form. I tried it at my end, it works. – Talk2Nit Jan 20 '18 at 16:05
  • The problem you have is that you probably have your submit button out of you form id="filterform" that's why when you try to get it back on the other file the variable "is not found". I mean if you have the submit button out the form you would be sending all the values that are outside this form and not the ones you need make the php part of your code to work as expected – Art_Code Jan 20 '18 at 16:07
  • Hi @FunkFortyNiner Yes I did. – alexvin Jan 21 '18 at 07:55
  • @JulioPérez I have it inside as in the code. It still does not work – alexvin Jan 21 '18 at 07:56
  • @NitinKawane Hey, sorry I just updated it and edited the code. Please kindly view it above. Thank you – alexvin Jan 21 '18 at 07:57
  • @alexvin Try a simple example with 2 files. 1st file will have a form with a checbox and a submit button. 2nd file will have the isset validation of the checkbox and see if it works (it will) then add step by step your code (modal etc) and test each time you add something new to the example file. That way is easy to debug and you will fix the error – Art_Code Jan 21 '18 at 12:00
  • Maybe it has to do with the modal. Are you getting other values sended from your modal? We don't have the entire code of the modal so we can't test it as we need to find the error. If you can't share more code then please try what I mentioned above about the example with 2 files – Art_Code Jan 21 '18 at 12:02
  • Hi, @JulioPérez Thank you for your reply. Yes I did that method to debug. I realised I can either send the input type text at a time or input type checkbox. I cant send both at the same time for some. I can combine the both for some reasons. Is there a way I could send you my code? – alexvin Jan 21 '18 at 13:20
  • Yes, by chat here on stackoverflow but i really don't know how to start "chat mode" xD – Art_Code Jan 21 '18 at 13:51

1 Answers1

0

There is no submit button or a javascript that is submitting your form, so the php is never executed

try adding <input type="submit"> in your form

if you want to execute the php as soon ad the checkbox is clicked you nee to use some javascript to tell the browser to submit the form when it gets a click on an input field.

Nathanael
  • 870
  • 5
  • 11