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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:49:08+00:00 2026-05-31T02:49:08+00:00

I have 2 sets of 4 input fields in my HTML Form. I expect

  • 0

I have 2 sets of 4 input fields in my HTML Form. I expect to eventually have over 20 sets but have provided just 2 for this example.

Is it possible if a “set” of fields is incomplete that I can just remove that row from my resultant $all variable. So instead of having a row with the data ‘| | | |’ it would just be completely blank.

It would just help clean things up.

Would this be easy enough to achieve?

Here is my current stuff.php script I’m using to test.

<html>

<head>

<title>Test PHP</title>

</head>

<body>

<?php

if (isset($_POST['sendform'])) {


    $ierrors = array();
    $all = '';

    // Loop over the values 1 through 2
    foreach( range( 1, 2) as $i)
    {
        // Create an array that stores all of the values for the current number
        $values = array( 
            'p' . $i . 'height' => $_POST['p' . $i . 'height'], 
            'p' . $i . 'width' => $_POST['p' . $i . 'width'], 
            'p' . $i . 'length' => $_POST['p' . $i . 'length'], 
            'p' . $i . 'weight' => $_POST['p' . $i . 'weight']
        );

        // Validate every value
        foreach( $values as $key => $value)
        {
            if( empty( $value))
            {
                $ierrors[] = "Value $key is not set";
            }
            // You can add more validation in here, such as:
            if( !is_numeric( $value))
            {
                $ierrors[] = "Value $key contains an invalid value '$value'";
            }
        }

        // Join all of the values together to produce the desired output
        $all .= implode( '|', $values) . "\n\n";
    }   

    var_dump($all);

}

?>

<form action="stuff.php" method="post">

    <div id="npup0" class="hidden">
        <div class="parcel-group"> 
            <div class="parcel-title"> 
              <label for="p1weight">Parcel 1</label> 
            </div> 
            <div class="minis weight"> 
              <input type="text" id="p1weight" name="p1weight" value="<?php if ((isset($_POST['sendform'])) && (!empty($_POST['p1weight']))) { echo htmlspecialchars($_POST['p1weight']); } ?>" onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;" /> 
            </div> 
            <div class="minis length">  
                <input type="text" id="p1length" name="p1length" value="<?php if ((isset($_POST['sendform'])) && (!empty($_POST['p1length']))) { echo htmlspecialchars($_POST['p1length']); } ?>" onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;" /> 
            </div> 
            <div class="minis width"> 
                <input type="text" id="p1width" name="p1width" value="<?php if ((isset($_POST['sendform'])) && (!empty($_POST['p1width']))) { echo htmlspecialchars($_POST['p1width']); } ?>"  onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;" /> 
            </div> 
            <div class="minis height">  
                <input type="text" id="p1height" name="p1height" value="<?php if ((isset($_POST['sendform'])) && (!empty($_POST['p1height']))) { echo htmlspecialchars($_POST['p1height']); } ?>" onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;" /> 
            </div> 
        </div>
    </div>

    <div id="npup1" class="hidden">
        <div class="parcel-group"> 
            <div class="parcel-title"> 
              <label for="p1weight">Parcel 2</label> 
            </div> 
            <div class="minis weight"> 
              <input type="text" id="p2weight" name="p2weight" value="<?php if ((isset($_POST['sendform'])) && (!empty($_POST['p2weight']))) { echo htmlspecialchars($_POST['p2weight']); } ?>" onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;" /> 
            </div> 
            <div class="minis length"> 
            <input type="text" id="p2length" name="p2length" value="<?php if ((isset($_POST['sendform'])) && (!empty($_POST['p2length']))) { echo htmlspecialchars($_POST['p2length']); } ?>" onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;" /> 
            </div> 
            <div class="minis width"> 
            <input type="text" id="p2width" name="p2width" value="<?php if ((isset($_POST['sendform'])) && (!empty($_POST['p2width']))) { echo htmlspecialchars($_POST['p2width']); } ?>" onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;" /> 
            </div> 
            <div class="minis height"> 
            <input type="text" id="p2height" name="p2height" value="<?php if ((isset($_POST['sendform'])) && (!empty($_POST['p2height']))) { echo htmlspecialchars($_POST['p2height']); } ?>" onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;" /> 
            </div> 
        </div>
    </div>

    <p><input type="submit" value="click me" id="sendform" name="sendform" /></p>

</form>

</body>

</html>

Many thanks for any pointers. Been struggling with this for a while now.

  • 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-31T02:49:10+00:00Added an answer on May 31, 2026 at 2:49 am

    Yes, provide a condition that only concatenates $values with $all as long as $values isn’t empty.

    // Assume all values are empty.
    $allEmpty = true;
    
    // Validate every value
    foreach( $values as $key => $value)
    {
        if( empty($value))
            $ierrors[] = "Value $key is not set";
        else
            $allEmpty = false;
    
    
        // You can add more validation in here, such as:
        if( !is_numeric( $value) ) 
            $ierrors[] = "Value $key contains an invalid value '$value'";
    }
    
    // Join all of the values together to produce the desired output
    if (!$allEmpty)
        $all .= implode( '|', $values) . "\n\n";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form that sets input fields as enabled / disabled based on
I have two sets of of input fields like this, differentiated by their classes:
I have a number of sets of input fields on page, like this: <div
I have 3 sets of 4 input fields that I want the user to
Suppose I have the following HTML form: <form> ... <input type=submit name=queue value=Queue item>
I have a form input with a label next to it, like this: <div
I have a select input on my page. this select input displays/hides fields in
I am trying to think data in terms of sets but have some questions
i have an example of a source code which programatically sets the value of
I have a table in a form with a loop around it that sets

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.