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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T22:50:54+00:00 2026-06-09T22:50:54+00:00

I’m new to PHP, and have spent 10 hours trying to figure this problem

  • 0

I’m new to PHP, and have spent 10 hours trying to figure this problem out.

The goal is to take all data entered into this order form, and send it to my email via PHP.

I have 2 questions:

1. I can get PHP to send data from a single menu item (example: Mexican Tortas), but how do I get PHP to send data from multiple items (example: Mexican Tortas, Fish Sandwich and Hamburger)?

2. How do I tell PHP to not send data from menu items that don’t have the “How Many?” or “Customize It?” text fields filled out?

If you could provide a super simple example (or a link to a learning resource) I would really appreciate it.

Thank you,
Abijah


PHP

<?php
if(isset($_POST['submit'])) {

$to = "test@mywebsite.com"; 
$subject = "New Order";
$name_field = $_POST['name'];
$phone_field = $_POST['phone'];
$item = $_POST['item'];
$quantity = $_POST['quantity'];
$customize = $_POST['customize'];

}

$body = "Name: $name_field\nPhone: $phone_field\n\nItem: $item\nQuantity: $quantity\nCustomize: $customize";

echo "Data has been submitted to $to!";
mail($to, $subject, $body);

?>

HTML

<form action="neworder.php" method="POST">

<div class ="item">
<img style="float:left; margin-right:15px; border:1px Solid #000; width:200px; height:155px;" src="images/mexicantortas.jpg">
<h1>Mexican Torta - $8.50</h1>
<input name="item" type="hidden" value="Mexican Torta"/>
<h2>How Many? <font color="#999999">Ex: 1, 2, 3...?</font></h2> 
<input name="quantity" type="text"/>
<h3>Customize It? <font color="#999999">Ex: No Lettuce, Extra Cheese...</font></h3> 
<textarea name="customize"/></textarea>
</div><!-- ITEM_LEFT -->

<div class ="item">
<img style="float:left; margin-right:15px; border:1px Solid #000; width:200px; height:155px;" src="images/fishsandwich.jpg">
<h1>Fish Sandwich - $8.50</h1>
<input name="item" type="hidden" value="Fish Sandwich"/>
<h2>How Many? <font color="#999999">Ex: 1, 2, 3...?</font></h2> 
<input name="quantity" type="text"/>
<h3>Customize It? <font color="#999999">Ex: No Lettuce, Extra Cheese...</font></h3> 
<textarea name="customize"/></textarea>
</div><!-- ITEM_LEFT -->

<div class ="item">
<img style="float:left; margin-right:15px; border:1px Solid #000; width:200px; height:155px;" src="images/hamburgers.jpg">
<h1>Hamburger w/ Fries - $7.00</h1>
<input name="item" type="hidden" value="Fish Sandwich"/>
<h2>How Many? <font color="#999999">Ex: 1, 2, 3...?</font></h2> 
<input name="quantity" type="text"/>
<h3>Customize It? <font color="#999999">Ex: No Lettuce, Extra Cheese...</font></h3> 
<textarea name="customize"/></textarea>
</div><!-- ITEM_LEFT -->

<div class="horizontal_form">
<div class="form">
<h2>Place Your Order Now: <font size="3"><font color="#037B41">Fill in the form below, and we'll call you when your food is ready to be picked up...</font></font></h2>
<p class="name">
<input type="text" name="name" id="name" style="text-align:center;" onClick="this.value='';" value="Enter your name"/>
</p>
<p class="phone">  
<input type="text" name="phone" id="phone" style="text-align:center;" onClick="this.value='';" value="Enter your phone #"/>
</p>
<p class="submit">
<input type="submit" value="Place Order" name="submit"/>
</p>
</div><!-- FORM -->
</div><!-- HORIZONTAL_FORM -->

</form>
  • 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-09T22:50:55+00:00Added an answer on June 9, 2026 at 10:50 pm

    I suggest you use ‘[]’, as it groups multiple input fields to an array.

    <?php
    
    if ($_SERVER['REQUEST_METHOD'] == 'POST') {
      $_POST = filter_input_array(INPUT_POST, FILTER_SANITIZE_SPECIAL_CHARS);
    
      $to = "test@mywebsite.com"; 
      $subject = "New Order";
    
      $order = array();
      $order['name']  = $_POST['name'];
      $order['phone'] = $_POST['phone'];
    
      $food = $_POST['food'];
    
      foreach ($food as $type => $value)
        if (strlen($value['quantity']) > 0) // assuming 'customize' is optional
          $order[$type] = $value;
    
      print_r($order);
    }
    
    ?>
    
    <html>
    <head>
      <title>Order now!</title>
      <style>label,input,textarea {display:block}</style>
    <body>
    <?php // You need enctype for '[]' support' ?>
    <form action="" method="post" enctype="multipart/form-data">
      <div class ="item">
        <label>Mexican Torta - $8.50</label>
    
        <b>How Many?</b> 
        <input name="food[mexican_torta][quantity]" type="text">
    
        <b>Customize It? <font color="#999999">Ex: No Lettuce, Extra Cheese...</font></b> 
        <textarea name="food[mexican_torta][customize]"></textarea>
      </div>
    
      <div class ="item">
        <label>Fish - $3.50</label>
    
        <b>How Many?</b> 
        <input name="food[fish][quantity]" type="text">
    
        <b>Customize It? <font color="#999999">Ex: No Lettuce, Extra Cheese...</font></b> 
        <textarea name="food[fish][customize]"></textarea>
      </div>
    
      <h2>Place Your Order Now:</h2>
    
      <em>Fill in the form below, and we'll call you when your food is ready to be picked up.</em>
    
      <label>Enter your name</label>
      <input type="text" name="name">
    
      <label>Enter your phone nr.</label>
      <input type="text" name="phone">
    
      <button>Submit</button>
    </form>
    </body>
    

    User submits (for example I left the fish blank) and you get

    Array ( 
     [name] => Fab 
     [phone] => 1212
     [mexican_torta] => Array ( [quantity] => 2 [customize] => Test ) 
    )
    

    Play around a bit with the ‘[]’ to get the array output you really desire. The print_r will show you exactly what you get. From here it is really easy to put the food details in the e-mail

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a jquery bug and I've been looking for hours now, I can't
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from
I know there's a lot of other questions out there that deal with this

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.