I working on altering a php script that validates a form. My changes are not working correctly and I think because one of the post variables is an array which is the form data I need to verify if null.
here is the first part of the script based on form submission
if (isset($HTTP_POST_VARS)) {
$frm = $HTTP_POST_VARS;
print('<pre>');
print_r($frm);
print('</pre>');
$errormsg = validate_form($frm, $errors);
if (empty($errormsg)) {
//need code to post vars to cart_add.php if true
}
}
this is the function:
function validate_form(&$frm, &$errors) {
/* validate a given form, and return the error messages in a string. if
* the string is empty, then there are no errors */
$errors = new Object;
$msg = "";
if ($_POST['name'] == "Personalized Fun Stickers")
{
if (empty($frm["First_Name"])) {
print('<pre>');
print_r($frm["First_Name"]);
print('</pre>');
$errors->First_Name = true;
$msg .= "<li>You did not specify a First Name";
}
}
return $msg;
}
?>
I have multiple forms so it first verifies what form to validate. The $frm["First_Name"] is a value from the form. Here is a snippet of the input of the form.
<FORM name="personalization" method="post" action="<?=$PHP_SELF?>">
<tr><td class="personalization" Height="18" valign="center">Child’s First Name: <input type="text" name="personalize[First_Name]" value=<?= $frm["First_Name"] ?>></td></tr>
here is what print_r returns for $frm
Array
(
[personalize] => Array
(
[First_Name] => Alex
)
[id] => 1015
[name] => Personalized Fun Stickers
[price] => 3.95
[category] => Stickers
[cat] =>
)
and I get an error message for the $frm["First_Name"] in the validate form function.
Notice: Undefined index: First_Name in
The function works if the personlalize array didnt exist but I need the array because it is a collection of data used to personalize the item that I input as string variable in the database.
What would be the best approach to get at the form variables. Secondly I need to post the variables to another form. What would be the code pass the data if the $errormsg variable is empty, since my form action is to PHP_Self?
Your help would be greatly appreciated.
Alex