0

I have a form comprising of a checkbox list. Instead of the values being pre-determined in the code, I would like for the values to be fed in by the end-user. The value content has to be Date and time. Is this something that can be done? If so kindly point out how I can achieve this.

Please find below my html form for clarification:

<html>
<body>
<form method="post" action="chk123.php">
Flights on: <br/>


<input type="checkbox" name="Days[]" value="Daily"> <input type="datetime-local" value="bdaytime"> <br>
<input type="checkbox" name="Days[]" value="Sunday">Sunday<br>
<input type="checkbox" name="Days[]" value="Monday">Monday<br>
<input type="checkbox" name="Days[]" value="Tuesday">Tuesday <br>
<input type="checkbox" name="Days[]" value="Wednesday">Wednesday<br>
<input type="checkbox" name="Days[]" value="Thursday">Thursday <br>
<input type="checkbox" name="Days[]" value="Friday">Friday<br>
<input type="checkbox" name="Days[]" value="Saturday">Saturday <br>
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>

My php code:

<?php

// Make a MySQL Connection
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("test") or die(mysql_error());

$checkBox = implode(', ', $_POST['Days']);
$checkBoxArray = explode(" ", $checkBox);

if(isset($_POST['submit']))
{       
    $checkBox = implode(' ', $_POST['Days']);
    $checkBoxArray = explode(" ", $checkBox);

foreach ($checkBoxArray as $value)
   {
     $query="INSERT INTO example (orange) VALUES ('" . $value . "')";     
      mysql_query($query) or die (mysql_error() );
   }

    echo "<br />Complete";
}

?>
SirBT
  • 1,580
  • 5
  • 22
  • 51

1 Answers1

1

The type="datetime-local" is not widely supported by browsers as yet and the browser defaults to a normal text box. It is safer to use a calendar popup/widget. Jquery UI has the easiest to install and configure IMHO.

  • Thank you, I aware of this. I am designing this for personal use, so I will be using the appropriate browsers. It would be great if there was a solution were I could choose both type="datetime-local" and type="checkbox" for one single text field. Any advice or solution in mind? – SirBT Nov 25 '13 at 06:47
  • You will have to use JAvaScript to toggle between the text input and the checkbox input. –  Nov 25 '13 at 06:55