Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

echoing checkbox value

Explorer ,
Aug 30, 2011 Aug 30, 2011

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?

TOPICS
Server side applications

Views

689
Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 30, 2011 Aug 30, 2011

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.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 31, 2011 Aug 31, 2011

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?

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Sep 02, 2011 Sep 02, 2011

Copy link to clipboard

Copied

change this $_POST[noIdentity]

to this $_POST['noIdentity']

and do the same for your others

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 05, 2011 Sep 05, 2011

Copy link to clipboard

Copied

LATEST

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

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines