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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:06:58+00:00 2026-05-26T15:06:58+00:00

I am currently working on a Upload page, where users enter in values to

  • 0

I am currently working on a Upload page, where users enter in values to forms then click submit. I am going to check to see if the forms have been submitted, and if submitted that they weren’t empty. Here is my current code

function validPost()
{
    if(isset($_POST["title"]) && //if a post has been submitted
       isset($_POST["artist"]) &&
       isset($_POST["genre"]) &&
       isset($_POST["url"]) &&
       isset($_POST["user"]) ) 
    { 
        if (strlen($_POST['title']) <= 0) {
            echo 'ERROR: Please enter a title. </ br>';
            return false;
        }
        else if (strlen($_POST['artist']) <= 0) {
            echo 'ERROR: Please enter an artist. </ br>';
            return false;
        }
        else if (strlen($_POST['genre']) <= 0) {
            echo 'ERROR: Please select a genre. </ br>';
            return false;
        }
        else if (strlen($_POST['url']) <= 0) {
            echo 'ERROR: Please enter a url. </ br>';
            return false;
        }
        else if (strlen($_POST['user']) <= 0) {
            echo 'ERROR: Please enter a username to submit the song (or make one up). </ br>';
            return false;
        }
        else
            return true;
    }
    else //if no post was submitted
    { 
        return false;
    }
}

Is there a more elegant way to check this? I plan on adding more checks in the future to the content submitted by these forms and I feel like this is a sloppy way to do it.

Thanks!

  • 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-26T15:06:59+00:00Added an answer on May 26, 2026 at 3:06 pm

    Assuming that all of the fields will be check for non-zero string lengths only:

    $field_checks = array(
    //   'fieldname' => 'errormessage'
       'title' => 'Please enter a title',
       'url' => 'Please enter a URL',
       etc...
    );
    
    $errors = array();    
    foreach ($field_checks as $field => $errmsg) {       
        if (!isset($_POST[$field]) || ($_POST[$field] === '')) {
            $errors[] = $errmsg;
        }
    }
    
    if (count($errors) > 0) {
         print_r($errors); // probably want a nicer error display than this
         return false;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently working on a project where users can upload datasets in CSV format.
Am currently working on an application that requires users to submit posts and comments
I’m currently working on a website that will enable users to upload certain types
Basically, I have a page where users can upload their profile picture. However, if
I have a form where users can upload an image. I have another page
A site I am currently working with allows users to upload images onto a
I have my html5 form working to upload multiple mp3 files with one submit
I'm currently using SWFUpload to upload files to my S3 bucket. And it's working
I`m currently working on a script, and I have the following situation. function somnicefunction()
I have a Websphere Portal application containing several portlets for which I'm currently working

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.