Jump to content

If Checkbox is checked, post Data else...


louisstephens
 Share

Recommended Posts



<?php
if ($page->footerChecked->check == 1){ // 1 is checked, 0 is unchecked
echo $page->footerSelect->footerPost;
}

else{
echo "Fail";
}

?>

However, it still is posting "fail". Did I overlook something, or are checkboxes not supposed to be used this way.

Sorry for any confusion:

I have a template (storeFooter.php) which has 2 fields : footerChecked & footerPost. What I was trying to do was if the footerChecked was selected, display "footerPost". However, if it was not checked, display some random text.

Link to comment
Share on other sites

No worries. It's not specific to PHP as you can't always guarantee a true or false response from the above code, just I know true or false is what is returned for PricessWire's checkbox values when using them in frontend templates.

The actual printed value if you echo'd it would be a 1 I think if it was checked, else blank. It's always worth echoing a field to see what the actual value is, so

echo $page->footerChecked
in this instance.

Other fields will return different values - some arrays of pages so let us know if you get stuck with anything else - there's plenty of help around the forums :)

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...