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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:40:09+00:00 2026-05-30T21:40:09+00:00

I have an array of site options. Then I’ve a function that validates all

  • 0

I have an array of site options.

Then I’ve a function that validates all the data submitted by my users using foreach loop. You won’t know where most of the variables come from, but this is not important in this case:

function settings_validation($input) {
    $settings = my_array();   
    foreach ($settings as $setting) {

       //this function leaves the old field's value if there's no input
       if($type == 'something' && empty($input[$id])) {
           $valid_input[$id] = $option[$id];
       } 
       //this function updates the field if input is not NULL
       else if($type == 'something' && !empty($input[$id])) {
           $valid_input[$id] = $input[$id];
    }   

    return $valid_input;
};    

$input is an array of all form fields generated after submit, if field is empty it’s value is ” “.

Now, here comes the trouble.

When I want to erase one of the fields, it’s impossible – when I leave no data within this field and submit form it sends no data and always fires the first if statement and leaves the field in the state before erasing.

If I delete the first if statement then submit the form it sends new data to the options I’ve edited and erases all the others (as their $inputs are empty).

I’m not sure what kind of checks should I do to tell the difference between an empty $input generated by the function and and empty $input created by user’s action?

The settings_validation() function I’m using is a callback for other function called register_setting(), I’m asking here because not on WPSE it’s rather PHP related issue.

  • 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-30T21:40:10+00:00Added an answer on May 30, 2026 at 9:40 pm

    The answer was incrediby simple and pretty tricky:

    function settings_validation($input) {
    $settings = my_array();   
    foreach ($settings as $setting) {
    
       if($type == 'something' && empty($input[$id])) {
           //nothing here and everything is fine
       } 
    
       else if($type == 'something' && !empty($input[$id])) {
           $valid_input[$id] = $input[$id];
       }   
    
    return $valid_input;
    };    
    

    Thanks for helping!

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

Sidebar

Related Questions

I have array like this: $path = array ( [0] => site\projects\terrace_and_balcony\mexico.jpg [1] =>
I have an array of numbers that potentially have up to 8 decimal places
I have an array of a few million numbers. double* const data = new
I have a directory on my site that I've implemented PEAR's Auth to run
I'm using the jQuery UI's autocomplete function on a search on my site. When
I have been using the following preload script to load all the images and
I have created an attribute that accepts a (params) array in its constructor. internal
Let's suppose that we have multi-site CMS and every website in this CMS having
I've read online (on Google's own recommendations for site optimisation techniques) that using cookies
I have 2 select lists ausers - List all available users susers - Displays

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.