lundi 26 juin 2017

PHP Checkbox Assign To Variable

This is what I am after here. If the checkbox is checked, then I want to assign these values

$begindate = '20160101';
$enddate = '20161231'

If the checkbox is NOT checked then I want to force the user to select from the date selectors, and if either date is null then throw an error. I have this syntax, and the issue I am having with it is that if the check box is checked AND the user inputs dates then the input dates over-write the checkbox dates. NOT what I want to happen. There may be other syntax flaws in here that my new self has not realized yet, but what needs to be changed in this syntax in order to make it flow properly and execute as I describe above?

    <body>
<form>
Display 2016 Data? &emsp; <input type = 'Checkbox' Name='twentysix' value="twentysix"><br>
<input type="submit" name="submit" value="Gather">
</form>
</body>
<?php
if (isset($_POST['submit'])) 
{
    if ( isset($_POST['twentysix']) ) {
        $begindate = '20160101';
        $enddate = '20161231'
    } else {
        $begindate = $begindate;
        $enddate = enddate;
    }
    $begindateerror = false;
    $enddateerror = false;
    if (empty($_POST['begindate'])) {
        $begindateerror = true;
    }
    if (empty($_POST['enddate'])) {
        $enddateerror = true;
    }
    if ($begindateerror) {
    echo "<strong>Please select a start date.</strong><br>";
    } else if ($enddateerror) {
        echo "<strong>Please select a end date.</strong><br>";
    } else {
        $begindate = $_POST['begindate'];
        $enddate = $_POST['enddate'];
    }
}




Aucun commentaire:

Enregistrer un commentaire