I've been trying to figure this out for a while now and having issues as im new to PHP.
I need to have a checkbox that has to be checked before the form will be submitted to the database (registration form needing them to confirm the useragreement).
I am not sure where im going wrong and even after going through the other couple of posts on this matter im not having any luck with it.
below is the main bits of code that apply and anyone that could offer some guidance it would be much appreciated.
(the specific code for the check box is at the bottom of each portion as its the latest addition to the form)
From the validation
public function check($source, $items = array()) {
foreach($items as $item => $rules) {
foreach($rules as $rule => $rule_value) {
$value = trim($source[$item]);
if($rule === 'required' && $rule_value === true && empty($value)) {
$this->addError("{$item} is required.");
} else if (!empty($value)) {
switch($rule) {
case 'min':
if(strlen($value) < $rule_value) {
$this->addError("{$item} must be a minimum of {$rule_value} characters.");
}
break;
case 'max':
if(strlen($value) > $rule_value) {
$this->addError("{$item} must be a maximum of {$rule_value} characters.");
}
break;
case 'matches':
if($value != $source[$rule_value]) {
$this->addError("{$rule_value} must match {$item}.");
}
break;
case 'unique':
$check = $this->_db->get('users', array($item, '=', $value));
if($check->count()) {
$this->addError("{$item} is already in use.");
}
break;
case 'accepted':
if(!isset($_POST['useragreement'])){
$this->addError("You must agree to our terms and conditions");
}
break;
From the actual form processing
if(Token::check(Input::get('token'))) {
$validate = new Validate();
$validation = $validate->check($_POST, array(
'username' => array(
'required' => true,
'min' => 2,
'max' => 20,
'unique' => 'users'),
'password' => array(
'required' => true,
'min' => 6),
'password_again' => array(
'required' => true,
'matches' => 'password'),
'firstname' => array(
'required' => false,
'min' => 2,
'max' => 50),
'lastname' => array(
'required' => false,
'min' => 2,
'max' => 50),
'dob' => array(
'required' => false),
'gender' => array(
'required' => false),
'nationality' => array(
'required' => false),
'email' => array(
'required' => true,
'min' => 6,
'unique' => 'email'),
'email_again' => array(
'required' => true,
'matches' => 'email'),
'useragreement' => array(
'accepted' => true)
));
HTML
<div class="regfieldcheck">
<label for="useragreement"><span class="requiredfield">*</span> I agree to the User Agreement.</label>
<input id="useragreement" type="checkbox" />
</div>