PHP Forums Archive

How to add radio button to validation script 1.35?

Tags: validation, radio button

johnpro posted on 2008-11-20 14:34:28 #

It seems that it constantly shows me an error message as data will not be correct.

I kindly ask you to send me instructions how o fix this issue.

I have put the following into FORM:
<td class="text_form1"><input name="vatidcon" type="radio" value="1" checked="checked" /></td>
<td class="text_form1"><input name="vatidcon" type="radio" value="0" /></td>

and above into validator:
$example->add_text_field("VATID", $_POST['vatidcon'], "radio", "y");

Why it shows and error that input is not valid?
I noticed there are tow possibilities: checkbox and radio button.

I kindly ask you to help me soon as possible.

Comments / discussions

Olaf posted on 2008-11-20 14:55:30 #

it must be:

$example->add_check_box("some_name", "fieldname", "radio");

johnpro posted on 2008-11-28 14:02:32 #

Hi I have done, but still message error 12.
Is there some obligation for values in form. I have currently two values:
<td><input name="vatidcon" type="radio" value="1" checked="checked" /></td>
<td><input name="vatidcon" type="radio" value="0" /></td>

and validation code:
break;
case "checkbox":
case "radio":
if (!$this->check_check_box($val['value'], $key, $val['element'])) {
$status++;
}

and
function add_check_box($name, $element_name, $type = "radio", $required_value = "n") {
$this->fields[$name]['value'] = $required_value;
$this->fields[$name]['type'] = $type;
$this->fields[$name]['element'] = $element_name;
}

and
function check_check_box($req_value, $field, $element) {
if (empty($_REQUEST[$element])) {
$this->messages[] = $this->error_text(12, $field);
return false;
} else {
if (!empty($req_value)) {
if ($req_value != $_REQUEST[$element]) {
$this->messages[] = $this->error_text(12, $field);
return false;
} else {
return true;
}
} else {
return true;
}
}
}

It reports error 12:
$msg[12]

johnpro posted on 2008-11-28 14:04:06 #

I have change as you advised me:
$example->add_text_field("some_name", $_POST['vatidcon'], "radio");

Olaf posted on 2008-11-28 15:07:39 #

Quote from: johnpro
"I have change as you advised me:
$example->add_text_field("some_name", $_POST['vatidcon'], "radio");"

you didn't, check my previous post

johnpro posted on 2008-12-01 09:11:54 #

Hi,
I'm sorry I do not understand what you mean. Please explain more.Is issue code and what is wrong?

Olaf posted on 2008-12-01 09:16:49 #

do you see the difference?

$example->add_text_field("some_name", $_POST['vatidcon'], "radio"); (wrong)

and

$example->add_check_box("some_name", "fieldname", "radio"); (OK)