Jump to content

Posting Checkbox value problem


louis_coetzee

Recommended Posts

function LegalTerms()

{

extract($_REQUEST);

echo $legal; //just to see the value

echo $terms; //

if ($legal !== 'yes')

{

echo 'You need to agree to the terms and must be of legal age if you want to register.';

}else

{

if ($terms !== 'yes')

{

echo 'You need to agree to the terms and must be of legal age if you want to register.';

}

}

}

for some reason the value of both checkboxes checked or not, their value's stay "yes"

 

this is the form:<div id="reg_form_box">

<input name="terms" type="checkbox" id="terms" value="yes">

I agree to the <a href="#" target="Terms">Terms Of Use.</a>

<br>

<input name="legal" type="checkbox" id="legal" value="yes">

I am of legal age to work in South Africa.

</div>

 

Please guys any help would be appreciated.

Thanks in advance.

Link to comment
https://forums.phpfreaks.com/topic/140513-posting-checkbox-value-problem/
Share on other sites

First of all you don't need a function to do this. Secondly why dont you use the <form> if you are using a form. I would do something like this:

 

index.php

<form method="post" action="submit.php">
<input name="terms" type="checkbox" id="terms" value="yes">
I agree to the <a href="#" target="Terms">Terms Of Use.</a>
<br>
<input name="legal" type="checkbox" id="legal" value="yes">
I am of legal age to work in South Africa. 
<input type="submit" value="submit">
</form>

 

submit.php

<?php
$terms = $_POST['terms'];
$legal = $_POST['legal'];

if($legal != 'yes')
{
echo "You need to agree to the terms and must be of legal age if you want to register.";
}
else
{
if($terms != 'yes')
{
echo "You need to agree to the terms and must be of legal age if you want to register.";
}
}
?>

 

You would need to modify that for your needs.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.