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

  • Home
  • SEARCH
  • 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 7728653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T05:46:20+00:00 2026-06-01T05:46:20+00:00

The problem: if i submit the html form and a textbox is left blank

  • 0

The problem:

if i submit the html form and a textbox is left blank
then i don’t want it to proceed to the echo segment,
but the problem is it does proceed.

<?php
        if(!isset($_POST['submit']) && empty($_POST['moon']) && empty($_POST['planet']))
        { 
?>

        <form name="form2" method="post" action="<?php echo($_SERVER["PHP_SELF"]);?>">
            <div>
                Write a planet name: <input name="planet" type="text"><br>
                Its moon: <input name="moon" type="text">
            </div>
            <div>
                <input type="submit" name="submit" value="submit">
            </div>
        </form>


 <?php
       }else{

            echo("Planet: ".$_POST['planet']. "<br>");
            echo("Moon: ". $_POST['moon'] . "<br>");
            echo "Successful.";

            }
?>

As you know isset() determines if a variable is set and not null but doesn’t check if it’s empty.

While logic seems my if statement, I modified it from:
if(!isset($_POST['submit']) && empty($_POST['moon']) && empty($_POST['planet']))

To:

  • if(!isset($_POST['submit']) && ($_POST['planet']=='') && ($_POST['moon']==''))
  • if(!isset($_POST['submit']))
  • if(!isset($_POST['planet']) && !isset($_POST['moon']))
  • if(empty($_POST['moon']) && empty($_POST['planet']))

and none of them worked.

So am I doing something wrong with my if statement? how can I not let it proceed to the Else segment while a textbox is empty? without more if and no nested statements please.

  • 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-06-01T05:46:22+00:00Added an answer on June 1, 2026 at 5:46 am

    When you submit a form, the submit button will be set, so isset($_POST['submit']) will be true, therefore !isset($_POST['submit']) will be false.

    When doing an if statement with the && comparison, all conditions must be true in order to execute that block of code, otherwise it goes to the else statement.

    What you need to do is actually have 2 comparison checks. Once to see if the form was never submitted and one to see if it was, and the text boxes are empty:

    <?php
    
       // Check if form was submitted
       if(!isset($_POST['submit'])
       {
          // Display the form
       }
       else
       {
          // Form was submitted, check if values are empty
          if(trim($_POST['planet'])=="" || trim($_POST['moon'])=="")
          {
             // One or more value is empty, do something
          }
          else
          {
             // Process form
          }
       }
    
    ?>
    

    I realize you are trying to avoid nesting, but in order for the logic to flow smoothly, and the code to remain readable, this is a necessary evil.

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

Sidebar

Related Questions

I have a little problem with javascript form submit issue, here is the script
I am having problem that when i am trying to submit the form by
I'm having a little problem with jQuery: I'm having .submit() defined on a form,
I am using the jQuery disable on submit plug-in but I have a problem.
so here's the problem I have one form, it outputs search results after submit,
I am having problem with this javascript function. If I want to submit a
I'm constructing a form. No problem there. Aside of a submit button, I have
I want to create a input textbox that does not require a <input type=text>
When client side submit a HTML form , it will send a form object
I don't find how to submit a form that's in a partial view. I've

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.