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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:15:02+00:00 2026-06-12T00:15:02+00:00

This is honestly the most finicky and inept language I’ve ever coded in. I’ll

  • 0

This is honestly the most finicky and inept language I’ve ever coded in. I’ll be glad when this project is good and over with.

In any case I have to us PHP so here’s my question.

I have an Array named $form_data as such:

$form_data = array 
('trav_emer_med_insur',
'trav_emer_single',
'trav_emer_single_date_go',
'trav_emer_single_date_ba',

'trav_emer_annual',
'trav_emer_annual_date_go',

'trav_emer_extend',
'trav_emer_extend_date_go',
'trav_emer_extend_date_ef',
'trav_emer_extend_date_ba',


'allinc_insur',

'allinc_insur_opt1',
'allinc_single_date_go',
'allinc_single_date_ba',

'allinc_insur_opt2',
'allinc_annual_date_go',
'allinc_annual_date_ba',



'cancel_insur',
'allinc_annual_date_go', 
'allinc_annual_date_ba',



'visitor_insur', 
'country_select',

'visitor_supervisa', 
'visitor_supervisa_date_go',
'visitor_supervisa_date_ba',

'visitor_student',
'visitor_student_date_go',
'visitor_student_date_ba',

'visitor_xpat',
'visitor_xpat_date_go',
'visitor_xpat_date_ba',

'txtApp1Name',
'txtApp2Name',
'txtApp1DOB',
'txtApp2DOB',
'txtApp1Add',
'txtApp1City',
'selprov',
'txtApp1Postal',
'txtApp1Phone',
'txtApp1Ext',
'txtApp1Email',
'conpref', );

These are the names of name=”” fields on an HTML form. I have verified that ALL names exist and have a default value of ” using var_dump($_POST).

What I want to do is very simple, using the $form_data as reference do this:

  • create a new array called $out_data which can handle the data to display on a regurgitated form.

The structure of $out_data is simple the key will be the name of the element from the other array $out_data[txtApp1Name] for example, and then the value of that key will be the value.

  • Now what I want is to first check to see if every name=”” is set or not, to eliminate errors and verify the data. Then regardless of whether it is set or not, create its placeholder in the $out_data array.

  • So if $_POST[$form_data[1]] (name is ‘trav_emer_single’) is not set create an entry in $out_data that looks like this $out_data([trav_emer_single] => “NO DATA”)

  • If $_POST[$form_data[1]] (name is ‘trav_emer_single’) is set create and entry in $out_data that looks like this: $out_data([trav_emer_single] => “whatever the user typed in”)

I have tried this code:

$out_data = array();
$count = count($form_data); 
for( $i = 0; $i < $count; $i++ ) 
{
    if(!isset($_POST[$form_data[$i]])) {
        $out_data[$form_data[$i]] = "NO_DATA";
        }
    else {
        $out_data[$form_data[$i]] = $_POST[$form_data[$i]];
        }
}

Now this code technically is working, it is going through the array and assigning values, but it is not doing so properly.

I have hit submit on the form with NOTHING entered. Therefore every item should say “NO_DATA” on my regurgitated output (for user review), however only some items are saying it. All items I have confirmed have name=”” and match the array, and have nothing entered in them. Why is “NO_DATA” not being assigned to every item in the array?

Also of note, if I fill in the form completely $out_data is fully and correctly populated. What is the problem with !isset? I’ve tried doing $_POST[$form_data[$i]] == ” which does put no_data in every instance of no data, however it throws an ‘undefined index’ warning for every single item on the page whether I write something in the box or not.

Really I just want to know WTF is going on, the dead line for this project is closing fast and EVERY step of the PHP gives me grief.

As far as I can tell by reading around my code is valid, but refuses to execute as advertised.

If you need more code samples please ask.

Really befuddled here, nothing works without an error, help please.

Thanks
-Sean

  • 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-12T00:15:03+00:00Added an answer on June 12, 2026 at 12:15 am

    Instead of checking !isset(), use empty(). If the form posts an empty string, it will still show up in the $_POST as an empty string, and isset() would return TRUE.

    I’ve replaced your incremental for loop with a foreach loop, which is almost always used in PHP for iterating an array.

    $out_data = array();
    foreach ($form_data as $key) {
        if(empty($_POST[$key])) {
            $out_data[$key] = "NO_DATA";
        }
        else {
            $out_data[$key] = $_POST[$key];
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my first question ever on StackOverflow, hurray! I can honestly say I
Preface : I'm honestly not sure if this should be on StackOverflow, SuperUser or
Somewhere some guy said (I honestly do not know where I got this from),
I have this Objective-C code that I found somewhere. Honestly, I don't understand a
Crappy title, yes. But I honestly have no idea what this particular line of
Would the most efficient way-and I know it's not very efficient, but I honestly
Are there any ways providing an alternate GIF/PNG image, in case the user has
I tried searching around for this, but honestly I'm not really sure exactly what
this is my first question in here, and I would like to ask if
This question is directly related to this SO question I posed about 15 minutes

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.