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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:32:15+00:00 2026-06-11T04:32:15+00:00

Okay so my title might be a little confusing, but let me explain my

  • 0

Okay so my title might be a little confusing, but let me explain my situation:

I have a pretty big form with lots of fields, some which are required, some which are not. I do validation with JS, but then I’m also doing validation on the server side with PHP.

One of the things I’m asking the user for is a “Header Name”. Now, header name has the name attribute of “header1”. The user has the option of adding more header fields on the form. So if they click a button it adds another “Header Name X” with name attribute “headerx”.

Got it? Now, the problem is, in general these header fields are not required, but I do have the condition that they MUST supply at least one Header field. So they could supply 100, they could supply 2, they might supply 1, but if they don’t supply any then validation should fail.

I can’t think of a good way of checking for this in PHP though. I know your fist thought is just check if $_POST contains anything. Won’t work though because they are multiple other fields in this form that are required that have nothing to do with these Headers. So I can’t just simply check to see if $_POST contains something because it always will.

Is there a way I can like combine isset() with a regular expression? Like isset($_POST[‘header{\d+}’]. Which would be saying like header with atleast one digit following it.

Thanks for the help!

EDIT: Oh and if this wasn’t hard enough already, the amount of Header Fields is limitless. So I can’t just loop through all the possible “headerx” because that would obviously be an infinite loop.

  • 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-11T04:32:17+00:00Added an answer on June 11, 2026 at 4:32 am

    You could have field names with []:

    <input type="text" name="foo[]" value="x" />
    <input type="text" name="foo[]" value="y" />
    

    Then $_POST would be like:

    array('foo' => array('x', 'y'));
    

    You could even have associative arrays:

    <input type="text" name="foo[bar][first]" value="x" />
    <input type="text" name="foo[bar][second]" value="y" />
    

    Would look like:

    array('foo' => array('bar' => array('first' => 'x', 'second' => 'y')))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay, the post title might be a little confusing. I have this code: class
Okay, this is a little hard to explain, as the title might suggest. I
Okay so the title might sound a bit confusing, but here's what I want
Okay the title cannot explain the situation correct enough. Now this is it, I
Okay so i have this code: if (isset($_GET['book'])) { $query= SELECT book_id, title, authors.`author`
Okay, next PHPExcel question. I have an HTML form that users fill out and
Okay, I'll admit - the title is not the most descriptive/helpful but I couldn't
You read the title and groaned. That's okay. I did too. But we do
Okay, so I have some code that worked fine in PHP4 but since upgrading
Okay, so you got the idea from title, let me just post the code

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.