In this code you need to add input checkbox and make it so that the form could be sent only after will mark this checkbox, how to do?

 
 
<p>Name: </p><p> <input type="text" name="name"> </p> <p>E-mail: </p><p> <input type="text" name="email"></p> <p>Message: </p><p> <textarea rows="10" cols="45" name="message"></textarea></p> <input type="submit" value="Send">

<? 
// ----------------------------configuration-------------------------- // 

$adminemail="admin@site.ru"; // email admin 


$date=date("d.m.y"); // the number.a month.year 

$time=date("H:i"); // hours:minutes:seconds 

$backurl="http://site.ru/index.html"; // what page goes after the letter is sent 

//---------------------------------------------------------------------- // 



// Accept the data from the form 

$name=$_POST['name']; 

$email=$_POST['email']; 

$msg=$_POST['message']; 



// Check for a valid email 

if (!preg_match("|^([a-z0-9_\.\-]{1,20})@([a-z0-9\.\-]{1,20})\.([a-z]{2,4})|is", 
strtolower($email))) 

 { 

 echo 
"<center-->go Back to <a href="javascript:history.back(1)"><b>back</b></a>. You 
indicated wrong data!"; 

 } 

 else 

 { 


$msg=" 


<p>Name: $name</p> 


<p>E-mail: $email</p> 


<p>Message: $msg</p> 


"; 



 // Send email to admin 

mail("$adminemail", "$date $time Message 
from $name", "$msg"); 



// Save to the database 

$f = fopen("message.txt", "a+"); 

fwrite($f," \n $date $time Message from $name"); 

fwrite($f,"\n $msg "); 

fwrite($f,"\n ---------------"); 

fclose($f); 



// Print a message to the user 

print "<script language="Javascript"><!-- 
function reload() {location = \"$backurl\"}; setTimeout('reload()', 6000); 
//--></script> 

$msg 

<p>Message sent! Wait, now you will be redirected to the main page.</p>"; 
exit; 

 } 

?>
June 14th 19 at 18:07
1 answer
June 14th 19 at 18:09
Solution
 
<p>Name: </p><p> <input type="text" name="name"> </p> <p>E-mail: </p><p> <input type="text" name="email"></p> <p>Message: </p><p> <textarea rows="10" cols="45" name="message"></textarea></p> <p>–°heckbox: </p><p> <input name="checkbox" type="checkbox"></p> <input type="submit" value="Send">
<? 
// ----------------------------configuration-------------------------- // 
$adminemail="admin@site.ru"; // email admin 
$date=date("d.m.y"); // the number.a month.year 
$time=date("H:i"); // hours:minutes:seconds 
$backurl="http://site.ru/index.html"; // what page goes after the letter is sent 
//---------------------------------------------------------------------- // 
// Accept the data from the form 
if ($_POST['checkbox']){
echo "I made a checkbox";
}
$name=$_POST['name']; 
$email=$_POST['email']; 
$msg=$_POST['message']; 
// Check for a valid email 
if (!preg_match("|^([a-z0-9_\.\-]{1,20})@([a-z0-9\.\-]{1,20})\.([a-z]{2,4})|is", 
strtolower($email))) 

 { 

 echo 
"<center-->go Back to <a href="javascript:history.back(1)"><b>back</b></a>. You 
indicated wrong data!"; 

 } 

 else 

 { 


$msg=" 


<p>Name: $name</p> 


<p>E-mail: $email</p> 


<p>Message: $msg</p> 


"; 



 // Send email to admin 

mail("$adminemail", "$date $time Message 
from $name", "$msg"); 



// Save to the database 

$f = fopen("message.txt", "a+"); 

fwrite($f," \n $date $time Message from $name"); 

fwrite($f,"\n $msg "); 

fwrite($f,"\n ---------------"); 

fclose($f); 



// Print a message to the user 

print "<script language="Javascript"><!-- 
function reload() {location = \"$backurl\"}; setTimeout('reload()', 6000); 
//--></script> 

$msg 
<p>Message sent! Wait, now you will be redirected to the main page.</p>"; 
exit; 
 } 
?>

Find more questions by tags HTMLLayoutPHP