Copy link to clipboard
Copied
I have a form, and if it is not sent, the form is echoed. here is part of my code that is being echoed:
echo "...<input type='checkbox' name='noIdentity' id='noIdentity' value='noIdentity'
<?php
if(isset($_POST[errors]) && isset($_POST[noIdentity])) {
echo 'checked=checked';
}
?>..."
The only problem is, if the value is checked, when i come back to it with the rest of the form errors, it is not checked. why isn't it being checked?
Copy link to clipboard
Copied
My gut is telling me that the noidentity isset check is failing. How are you setting $_POST[errors]? Are you submitting to a page and then redirecting back to the form and setting $_POST[errors] on that next page? If so, then what I suspect is happening is during the transition from page 1 -> page 2 -> page 1 is that your variables are not being reset. Have you considered storing the variables in a session during this process instead and then passing the session variables back if the form fails?
Only way to be more certain is to see more of the code.
Copy link to clipboard
Copied
i am setting post errors by doing something like this (on the same page):
if submit,
if(empty($_POST['message'])) {
$errors[] = "Please fill in a message.";
}
then:
if (isset($errors) && !empty($errors)) {
$result = count($errors);
for ($i=0; $i<$result; $i++) {
echo "<p><div class='error'><img src='../Images/error_image.png' width='16' height='16' /> $errors[$i]</div><p>";
}
}
what is the best way to submit a form? on the same page, or redirect? or does it depend on the situation?
Copy link to clipboard
Copied
change this $_POST[noIdentity]
to this $_POST['noIdentity']
and do the same for your others
Copy link to clipboard
Copied
hm, when i do that, i get this error:
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /homepages/45/htdocs/uploader/member_contact.php on line 238
I guess it doesn't like when I add the single quotes...