Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6966279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:10:16+00:00 2026-05-27T16:10:16+00:00

I have a simple form I created, and in it I have the following

  • 0

I have a simple form I created, and in it I have the following checkbox:

<input type="checkbox" name="test">

Note: this form is being submitted to itself.

Above the form, I have the following PHP:

if (empty($_POST['test'])) {
    $thevalue = 0;
} else {
    $thevalue = 1;
}
var_dump($thevalue);

When I process the form, I get what I would expect. If I check the box and submit, I get int(1) if I leave it unchecked I get int(0).


In the first line of my PHP code, I wanted to replace $_POST['test'] with some simple variable.

So I added the following line above my code:

$simplevar = $_POST['test']

I then replaced the condition in my if statement to be empty($simplevar)

But when I submit the form, I get a "Notice: Undefined index:" error message

  1. Why is this happening?
  2. Assuming it’s possible to achieve what I was after (i.e. insert $_POST into $simplevar), how might I go about it?

Thanks in advance for your help!

PS: I may have a follow up to this question, but didn’t want to clutter things by jamming it all in here.

Thanks again… oh, and Merry Christmas! 😉

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T16:10:17+00:00Added an answer on May 27, 2026 at 4:10 pm

    This happens because when you don’t check the checkbox, the browser does not send any value to server for that control when the form is submitted. Because of this, $_POST['test'] is not defined, and you tried to use it without a check as to whether it existed, so you get a warning. One of the checks that empty() does is to see whether the value is set. So, when you use the $_POST keys directly in empty(), you don’t get an error, but when you try and use it in an assignment without this check, you will get the error.

    You can do roughly what you want to do, you just have to change the logic slightly. If you do:

    $simplevar = !empty($_POST['test']);
    // You could also do
    // $simplevar = isset($_POST['test']);
    
    if ($simplevar) {
      // The box was checked
    } else {
      // The box was not checked
    }
    

    …it will do what you want without the error. Using this approach, $simplevar always holds a boolean indicating whether or not the box was checked.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple form like this: <form name=serachForm method=post action=/home/search> <input type=text name=searchText
I have simple form. <form target=_blank action=somescript.php method=Post id=simpleForm> <input type=hidden name=url value=http://...> <input
i have made a simple php contact form following this tutorial: http://www.catswhocode.com/blog/how-to-create-a-built-in-contact-form-for-your-wordpress-theme The big
I have created a simple test form with FormBorderStyle = FixedToolWindow by default and
I have a simple form right now: <form action='<? echo $PHP_SELF;?>' method='POST'> Username:<input type='text'
I am a bit confused. I have created a simple form with a one
I have created a simple web app/form using google app engine. the site is
I have simple form like this which accepts only two values string action and
I have a simple form setup and I was following how the book, Core
I have a simple email form: <form method=post action=process-form.php id=emailForm name=emailForm target=_self> <h4>Sign up

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.