vendredi 2 septembre 2016

php ajax checkbox always checked

I have a form to display quotes based on data recieved/checked.

It's a non-refreshing page, so it uses ajax get the submit click and then it sends data to php file.

The main problem is that the checkboxes are ALWAYS checked, and are echo'ing "ON". I need the checkboxes to work as normal, unchecked by default and then when user clicks on it, and submits the form they will actually be checked.

These are the checkboxes

<div class="checkbox">
        <label><input type="checkbox" name="lighting" id="lighting"><font color="#2C3E50" value="">Lighting</label></font>
        <label><input type="checkbox" name="heating" id="heating"><font color="#2C3E50" value="">Heating</label></font>
        <label><input type="checkbox" name="dancefloor" id="dancefloor"><font color="#2C3E50" value="">Dancefloor</label></font>
        <label><input type="checkbox" name="internaldressing" id="internaldressing" value=""><font color="#2C3E50">Internal Dressing</label></font>
    </div>

I tried removing value attribute, I tried adding checked attribute. literraly nothing helps.

This is part of the AJAX file:

    var dataString = 'eventtype=' + eventtype + '&peoplecount=' + peoplecount + '&location=' + location + '&eventdate=' + eventDate + '&lighting=' + lighting + '&heating=' + heating + '&dancefloor=' + dancefloor + '&internaldressing=' + internaldressing;


    $.ajax({  
    type: 'POST',  
    url: 'process.php',
    data: dataString,
    success: function(data) {
        if( data == '0' )
            alert( 'Błędne dane logowania!!!' );
        else
             $('#results').html(data);

    }  
}); 
        event.preventDefault();

And then my PHP looks like this.

if(isset($_POST)){

        // Total price of quote. 
        $price = 0;
        // Prices of extras. 
        $lighting_price = 0;
        $heating_price = 0;
        $dancefloor_price = 0;
        $internaldressing_price = 0;

        // Stage I VARIABLES
        $eventType = $_POST['eventtype'];
        $peoplecount = (int)$_POST['peoplecount'];
        $location = $_POST['location'];
        $eventDate = $_POST['eventdate'];

        // Stage II VARIABLES 
        $lighting = $_POST['lighting'];
        $heating = $_POST['heating'];
        $dancefloor = $_POST['dancefloor'];
        $internaldressing = $_POST['internaldressing'];

        // If there are less than 70 guests then make base price 650. 
        if($peoplecount < 70){
            $price = $price + 650;
            $lighting_price = 75; 
            $heating_price = 150;
        }

        // If there are between 71 and 130 guests then make base price 950.
        if(($peoplecount >= 71) && ($peoplecount <= 130)){
            $price = $price + 950;
            $lighting_price = 150;
            $heating_price = 250;
        }

        if (isset($_POST['lighting'])){
            echo "IM TICKEED!!!!!!!";
        }

        if (isset($_POST['heating'])){
            echo "IM TICKEED!!!!!!!";

        }

        echo $eventType . "<br>";
        echo $peoplecount . "<br>";
        echo $lighting . "<br>";
        echo $heating . "<br><br>";
        echo $price;

        }

Thanks for any help.




Aucun commentaire:

Enregistrer un commentaire