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 8053735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:56:52+00:00 2026-06-05T07:56:52+00:00

Possible Duplicate: More concise way to check to see if an array contains only

  • 0

Possible Duplicate:
More concise way to check to see if an array contains only numbers (integers)
PHP checking if empty fields

I have form that submits 10 fields, and 7 of them should be filled, here is how i chek it now in PHP:

if (!$name || !$phone || !$email || !$mobile || !$email || !$state || !$street || !  $city) {
        echo '<div class="empty_p">You have empty fields!!!</div>';}
else{
        //process order or do something
}

My question is: is there more simple way to do this? Because sometimes I have even more strings to check (12-15)

  • 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-05T07:56:53+00:00Added an answer on June 5, 2026 at 7:56 am
    <input type="text" name="required[first_name]" />
    <input type="text" name="required[last_name]" />
    ...
    
    
    $required = $_POST['required'];
    foreach ($required as $req) {
       $req = trim($req);
       if (empty($req))
          echo 'gotcha!';
    }
    

    /* update */

    OK! guys, easy…

    You can make it more secure, just with type casting as all we programmers do for out coming data, like $id = (int) $_GET['id'], like $username = (string) addslashes($_POST['username']) and so on…;

    $required = (array) $_POST['required'];

    And then, what ever comes from post fields let them come, this code just seek what it need.
    That is it! Uhh…

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

Sidebar

Related Questions

Possible Duplicate: More efficient way to remove elements from an array list I have
Possible Duplicate: More concise version of max/min without the block If I had N
Possible Duplicate: Python program to find fibonacci series. More Pythonic way. Hey, i was
Possible Duplicate: Is there a more efficent way to randomise a set of LINQ
Possible Duplicate: More efficient way of updating UI from Service than intents? I have
Possible Duplicate: Interview Q: sorting an almost sorted array (elements misplaced by no more
Possible Duplicate: How can JavaScript make new page that contains more JavaScript? I tried
Possible Duplicate: How can I check if a UILabel's value is more than 0
Possible Duplicate: Best way to stop SQL Injection in PHP my question is how
Possible Duplicate: Checking if an int is prime more efficiently I need to test

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.