Jump to content

PHP form - stops user proceeding until they have ticked checkboxes


annette50

Recommended Posts

Hi,

 

I'm sure this should be really easy! I need a simple form where the user has to agree to the terms and conditions - if they do (by checking a checkbox) they can proceed to the next page. If not, the page redirects to the submit form again with a reminder.

 

Very new at PHP so any help appreciated while I go through some tutorials!

 

Annette

Link to comment
Share on other sites

<?php

if(!$_POST['submit']){
echo "<form name=\"name\" method=\"post\" action=\"thispage.php\">\n";
echo "<table border=0 cellspacing=3 cellpadding=3>\n";
for($i=1;$i<=10;$i++){
echo "<tr><td>Checkbox $i</td><td><input type=\"checkbox\" name=\"list[]\" name=\"$i\"></td></tr>\n";
}
echo "<tr><td colspan=2 align=right><input type=\"submit\" name=\"submit\" value=\"Submit\"></td></tr>\n";
echo "</table></form>\n";
}else {
$list = $_POST['list'];

if($list){
	foreach($list AS $ids){
	echo $ids . "<br>\n";
	}
}else {
echo "No checkboxes ticked!\n";
}
}
?>

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.