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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:06:12+00:00 2026-06-17T14:06:12+00:00

I am self-learner and I am currently building (trying to build) a simple form

  • 0

I am self-learner and I am currently building (trying to build) a simple form that has a row with 3 fields, and which dynamically adds another row with the same fields depending on how many items the customer wants. It will have a limit of 20 items. I am using this html layout for the fields that are going to be added dynamically:

<div id="input1" style="margin-bottom:4px;" class="clonedInput">
        Part #: <input name="part'+i+'" type="text" id="part1" size="10" maxlength="15" />
        Description: <input name="description'+i+'" type="text" id="description1" size="30" maxlength="50" />
        Qty: <input name="quantity'+i+'" type="text" id="quantity1" size="5" maxlength="5" />
    </div>
    <p>&nbsp;</p>
    <div>
        <input type="button" id="btnAdd" onclick="dupForm('input', '.clonedInput', 'btnAdd', 'btnDel');" value="add item" />
        <input type="button" id="btnDel" onclick="rmForm('input', '.clonedInput', 'btnAdd', 'btnDel');" value="remove item" />
    </div>

and this java script:

function trimNums(stringToTrim)
{
return stringToTrim.replace(/\d+$/,””);
}

    function dupForm(divId, divClass, btnAdd, btnRm)
    {
    //alert(divId+'   '+divClass);
        var num     = $(divClass).length;
        var newNum  = new Number(num + 1);
        var i;

        var newElem = $('#' + divId + num).clone().attr('id', divId + newNum).fadeIn('slow');

        for (i=0; i < newElem.children().length; i++)
        {
            var attrId = trimNums(newElem.children(':eq('+i+')').attr('id'));
            var attrName = trimNums(newElem.children(':eq('+i+')').attr('name'));

            newElem.children(':eq('+i+')').attr('id', attrId + newNum).val('');
        }
        $('#' + divId + num).after(newElem);
        $('#' + btnRm).attr('disabled','');

        if (newNum == 20)
            $('#' + btnAdd).attr('disabled','disabled');
    }

    function rmForm(divId, divClass, btnAdd, btnRm)
    {
        var num = $(divClass).length;

        $('#' + divId + num).remove();
        $('#' + btnAdd).attr('disabled','');

        if (num-1 == 1)
            $('#' + btnRm).attr('disabled','disabled');
    }
    </script>

My question is: How can I get the variables into PHP so I can send this form to a specific email.

please note: I have more fields on the form and to gather the information in php I am using the following php script:

$emailField = $_POST['email'];
$company_nameField = $_POST['company_name'];
$dateField = $_POST['date'];
$phoneField = $_POST['phone'];

$part1Field = $_POST['part1'];
$part2Field = $_POST['part2'];

$description1Field = $_POST['description1'];
$description2Field = $_POST['description2'];

and to post it on the email i am using this to test:

$body = <<<EOD


Email: $email
Company Name: $company_name
Date: $date
Phone: $phone
$part1 | $description1 | $quantity1
EOD;

I know by gathering the variables of dynamic values, there needs to be a different code and I am stuck there. If someone can direct me to the right solution I will appreciate that very much.

  • 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-17T14:06:14+00:00Added an answer on June 17, 2026 at 2:06 pm

    You can use arrays:

    <div id="inputContainer">
        <div class="clonedInput">
            Part #: <input name="part[]" type="text" class="part" size="10" maxlength="15" />
            <button type="button" class="remove">Remove</button>
            <button type="button" class="clone">Clone</button>
        </div>
    </div>
    <div id="toolbar">
            <button type="button" class="add">Add new</button>
    </div>
    

    Using following code you can remove and clone individual inputs:

    var limit = 20;
    $('#inputContainer').on('click', '.clonedInput>.remove', function(e) {
        $(this).parent().fadeOut().remove();
        if ($(this).parent().parent().length < limit) {
            $('#toolbar>.add').removeAttr('disabled');
        }
    });
    
    $('#toolbar').on('click', '.add', function(e) {
        var newElem = $('<div class="clonedInput">\
            Part #: <input name="part[]" type="text" class="part" size="10" maxlength="15" />\
            <button type="button" class="remove">Remove</button>\
            <button type="button" class="clone">Clone</button>\
        </div>');
    
    
        $('#inputContainer').append(newElem);
        if($('#inputContainer').length == limit) {
            $('#toolbar>.add').attr('disabled', 'disabled');
        }
    });
    
    $('#inputContainer').on('click', '.clonedInput>.clone', function(e) {
        var newElem = $(this).parent().clone().fadeIn('slow');
    
        $(this).parent().after(newElem);
        if ($(this).parent().parent().length == limit) {
            $('#toolbar>.add').attr('disabled', 'disabled');
        }
    });
    

    See the fiddle.

    You can now access individual inputs fields in PHP using array keys:

    echo $_POST['part'][0]; // first 'part' field
    
    // print all fields
    $mailData = '';
    for($i = 0; $i < count($_POST['part']); $i++) {
        $mailData .= '#' . $_POST['part'][$i] . ' | ';
        $mailData .= $_POST['description'][$i] . ' | ';
        $mailData .= $_POST['quantity'][$i] . PHP_EOL;//or replace PHP_EOL for "<br>\n" it will work just fine
    
    }
    
    $body = <<<EOD
    Email: $email
    Company Name: $company_name
    Date: $date
    Phone: $phone
    $mailData
    EOD;
    
    
    your_mail_function($body);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building an application that needs to open self-signed HTTPS SSL URLs in java.
I am self- learner to android, Assume an android program is going to display
Pretty self explanatory. I have a textbox in an updatepanel that will autopostback when
I'm currently using mysql w/ PHP because that's what I learned and haven't ever
Possible Duplicate: How to find ancestor-or-self that is a child of an element with
I just learned yesterday from this site that I can: class Seq(object): def __init__(self,
I am a python learner and currently hacking up a class with variable number
I'm currently working with a part of my application that uses Dynamic Web User
I just recently learned about self calling anonymous functions. Some snippets of code that
We have received a HUGE project from outsourcing that we are trying to repair.

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.