Jump to content

yes no valadation on check box


redarrow

Recommended Posts

advance thank you.

I am using a date array function, and i wont the user to be able to say if they have any dates not to use
via a yes and no check box.

The varables for dates is:

[code]

$date1
$date2
$date3
$date4

[/code]

[code]
<input name="dates" type="checkbox" value="yes">Yes
<input name="dates" type="checkbox" value="no">no
[/code]


how do i get a valadition to see if the user has said no then dont insert to database, And if yes insert to database.

example only
[code]

if ($dates =="no") {

$date1 $date2 $date3 $date4

}else{


if($dates =="yes") {

$date1 $date2 $date3 $date4

INSERT INTO DATABASE
}
}
[/code]

So how do i join a no or yes to a corrersponding code.

or is this a existing proper code
[code]

if(($dates=="no")==($date1 && $date2 && $date3 && $date4)){
do nothink
}



if(($dates=="yes")==($date1 && $date2 && $date3 && $date4)){

INSERT INTO DATABASE

}

[/code]



Link to comment
Share on other sites

Might be better of using a radio button rather than a check box

[code]YES<input type=radio name=date1r value=yes>&nbsp;&nbsp;NO<input type=radio name=date1r value=no>
YES<input type=radio name=date2r value=yes>&nbsp;&nbsp;NO<input type=radio name=date2r value=no>
YES<input type=radio name=date3r value=yes>&nbsp;&nbsp;NO<input type=radio name=date3r value=no>
YES<input type=radio name=date4r value=yes>&nbsp;&nbsp;NO<input type=radio name=date4r value=no>[/code]

Ray
Link to comment
Share on other sites

Ray how to valadate a yes or no for the $date to be inserted to database mate

example all as one so if they press yes the insert goes if they press no the insert dosent go.


your code correct and nice thank you but one yes and one no ok

[code]
<input type=radio name=dates value=yes>Yes
<input type=radio name=dates value=yes>NO

[code]


what is the correct syntex code to join all as one together to valadate


example does this join a yes or no together with $dates.

if(($dates=="no")==($date1r && $date2r && $date3r && $date4r)){
do nothink
}



if(($dates=="yes")==($date1r && $date2r && $date3r && $date4r)){

INSERT INTO DATABASE

}
[/code]
Link to comment
Share on other sites

this on check.php

if you press yes echo yes if you press no echo no

is this correct not working


[code]

if(!$datecheck=="yes") {
echo "yes";
exit;
}


if(!$datecheck=="no") {
echo "no";
exit;
}

[/code]

this on post.php
[code]
<input name="datecheck" type="checkbox" value="yes">Yes
<input name="datecheck" type="checkbox" value="no">no
[/code]
Link to comment
Share on other sites

[!--sizeo:5--][span style=\"font-size:18pt;line-height:100%\"][!--/sizeo--]solved[!--sizec--][/span][!--/sizec--]


If the user press yes the database gets the dates, But if the user press no the user gets defult dates.

[code]

if($datecheck=="yes") {

$days = array();
$month = array();
$years = array();
foreach($_POST as $key => $value){
if (substr($key, 0, 5) == 'month'){
$months[]=$value;
}
if (substr($key, 0, 3) == 'day'){
$days[].=$value;
}
if (substr($key, 0, 4) == 'year'){
$years[]=$value;
}
}
$dates1 = ''.$days[0].'-'.$months[0].'-'.$years[0].'';
$dates2 = ''.$days[1].'-'.$months[1].'-'.$years[1].'';
$dates3 = ''.$days[2].'-'.$months[2].'-'.$years[2].'';
$dates4 = ''.$days[3].'-'.$months[3].'-'.$years[3].'';

INSERT INTO DATABASE

}

if($datecheck=="no") {

$dates1 ="0-0-0000";
$dates2 ="0-0-0000";
$dates3 ="0-0-0000";
$dates4 ="0-0-0000";


INSERT INTO DATABASE
}
[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.