jack-lindsay
asked on
insert data into textfield using checkbox
Hi guys,
what i have is a textfield which would have a date put in it. i also have a check box which will represent todays date <?php date("d/m/y "); ?>
what i would like is if the text field is blank and the checkbox is checked when the submit button is pressed, todays date is submitted to a mysql table. if the text field is blank and the check box is unchecked, i would like an error to appear.
any ideas where i can find something like this?
all advice is appreciated
kind regards
jack
what i have is a textfield which would have a date put in it. i also have a check box which will represent todays date <?php date("d/m/y "); ?>
what i would like is if the text field is blank and the checkbox is checked when the submit button is pressed, todays date is submitted to a mysql table. if the text field is blank and the check box is unchecked, i would like an error to appear.
any ideas where i can find something like this?
all advice is appreciated
kind regards
jack
Sorry, missed my closing php tag (?>), but you get the idea. :-)
First, change your checkbox value to a "constant value" such as "1" for example. We will do the date derivation in the processing page.
I have two strategies for you:
I have two strategies for you:
// REPLACE
// $_POST['textdate'] with your textbox variable
// $_POST['checkdate'] with your checkbox variable
// strategy 1 - check both values
// only make date today only if checkbox is checked only if textbox is blank
if ($_POST['checkdate'] == "1"){
if(isset($_POST['textdate'])){
}
else
{
$zdate = date("d/m/y ");
}
}
else
{
if(isset($_POST['textdate'])){
$zdate = $_POST['textdate'];
}else{
// error both inputs are blank
}
}
// strategy 2 - overwrite
// overwrite when checkbox is "checked" no matter what is in textbox
if ($_POST['checkdate'] == "1"){
$zdate = date("d/m/y ");
else {
if(isset($_POST['textdate'])){
$zdate = $_POST['textdate'];
}else{
// error both inputs are blank
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Note: No need to pass the current date as the value of your checkbox since you can just compute it when you process the form data.
Open in new window