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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T20:14:26+00:00 2026-06-16T20:14:26+00:00

I have a form which contain an autocomplete from database and then when submitted

  • 0

I have a form which contain an autocomplete from database and then when submitted by user it send the results to pdf and sending it to email.. but when I test it for one line it success but when add more lines the pdf give me the word “array” heres the codes.

the index.php

<?php require("login3.php"); ?>
 <?php
 if (!empty($_POST)) {

// Used for later to determine result
$success = $error = false;

// Object syntax looks better and is easier to use than arrays to me
$post = new stdClass;

// Usually there would be much more validation and filtering, but this
// will work for now.
foreach ($_POST as $key => $val)
    $post->$key = trim(strip_tags($_POST[$key]));

// Check for blank fields
if (empty($post->itemCode) OR empty($post->itemDesc) OR empty($post->itemQty) OR             empty($post->itemPrice) OR empty($post->itemAgent))
    $error = true;

else {

    // Get this directory, to include other files from
    $dir = dirname(__FILE__);

    // Get the contents of the pdf into a variable for later
    ob_start();
    require_once($dir.'/pdf.php');
    $pdf_html = ob_get_contents();
    ob_end_clean();

    // Load the dompdf files
    require_once($dir.'/dompdf/dompdf_config.inc.php');

    $dompdf = new DOMPDF(); // Create new instance of dompdf
    $dompdf->load_html($pdf_html); // Load the html
    $dompdf->render(); // Parse the html, convert to PDF
    $pdf_content = $dompdf->output(); // Put contents of pdf into variable for later  

    // Get the contents of the HTML email into a variable for later
    ob_start();
    require_once($dir.'/html.php');
    $html_message = ob_get_contents();
    ob_end_clean();

    // Load the SwiftMailer files
    require_once($dir.'/swift/swift_required.php');

    $mailer = new Swift_Mailer(new Swift_MailTransport()); // Create new instance of SwiftMailer

    $message = Swift_Message::newInstance()
                   ->setSubject('New Order') // Message subject
                   ->setTo(array('hussammoz@aol.com',  'hussammoz@gmail.com' => 'Orange Pharmacy Store')) // Array of people to send to
                   ->setFrom(array('no-reply@net.tutsplus.com' => 'Orange Pharmacy Order System')) // From:
                   ->setBody($html_message, 'text/html') // Attach that HTML message from earlier
                   - >attach(Swift_Attachment::newInstance($pdf_content, 'nettuts.pdf', 'application/pdf')); // Attach the generated PDF from earlier

    // Send the email, and show user message
    if ($mailer->send($message))
        $success = true;
    else
        $error = true;

}

   }
   ?>
       <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
      <html>
      <head>
   <title>Orange Pharmacy Order System</title>
   <style type="text/css" title="currentStyle">
            @import "css/layout-styles.css";
            @import "css/themes/smoothness/jquery-ui-1.8.4.custom.css";
</style>

<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />

<!-- jQuery libs -->
<script  type="text/javascript" src="js/jquery-1.6.1.min.js"></script>
<script  type="text/javascript" src="js/jquery-ui-1.8.14.custom.min.js"></script>

<!-- Our jQuery Script to make everything work -->
<script  type="text/javascript" src="js/jq-ac-script.js"></script>

</head>
<body>
<h1 align="center"><img src=418694_259331167468533_385322251_n.jpg></h1>
<div id="container">

    <div class="panel">
        <div class="title-large">
            <div class="theme"></div>
        </div>
 <p>
 <h1 align="center"><b>Branch : <FONT COLOR="ORANGE"><?php echo($_SESSION["username"]);   ?>   <h5 align="left"><font color="black">Date : </font></b><script type="text/javascript">
function GetClock(){
d = new Date();
nday   = d.getDay();
nmonth = d.getMonth();
ndate  = d.getDate();
nyear = d.getYear();
nhour  = d.getHours();
nmin   = d.getMinutes();
nsec   = d.getSeconds();

if(nyear<1000) nyear=nyear+1900;

 if(nhour ==  0) {ap = " AM";nhour = 12;} 
 else if(nhour <= 11) {ap = " AM";} 
 else if(nhour == 12) {ap = " PM";} 
 else if(nhour >= 13) {ap = " PM";nhour -= 12;}

 if(nmin <= 9) {nmin = "0" +nmin;}
 if(nsec <= 9) {nsec = "0" +nsec;}


 document.getElementById('clockbox').innerHTML=""+(nmonth+1)+"/"+ndate+"/"+nyear+"     "+nhour+":"+nmin+":"+nsec+ap+"";
setTimeout("GetClock()", 1000);
}
window.onload=GetClock;
</script>
<?php if ($success) { ?>
        <div class="message success">
            <h4>Congratulations! It worked! Now check your email.</h4>
        </div>
    <?php } elseif ($error) { ?>
        <div class="message error">
            <h4>Sorry, an error occurred. Try again!</h4>
        </div>
    <?php } ?>
  <div id="clockbox"></div></font></h5></h1>
            <div class="content inpad">

                   <div id="messageBox" style="margin-left:15px; padding-left:20px;   padding-bottom:5px; border:1px #ccc solid; display:none;"></div>

                        <form method="post" action="#" id="itemsForm">

                            <table id="itemsTable" class="general-table">
                                <thead>
                                <tr>
                                    <th></th>
                                    <th>Item Code</th>
                                    <th>Item Description</th>
                                    <th>Item Qty</th>
                                    <th>Item Price</th>
                                    <th>Item Agent</th>
                                </tr>
                                </thead>
                                <tbody>
                                    <tr class="item-row">
                                        <td></td>
                                        <td><input name="itemCode" value=""     class="tInput" id="itemCode" readonly="readonly" /> </td>
                                        <td><input name="itemDesc" value="" class="tInput" id="itemDesc"  tabindex="1"/></td>
                                        <td><input name="itemQty" value="" class="tInput" id="itemQty" tabindex="2"/></td>
                                        <td><input name="itemPrice" value="" class="tInput" id="itemPrice" readonly="readonly" /> </td>
                                        <td><input name="itemAgent" value="" class="tInput" id="itemAgent" readonly="readonly" /></td>
                                    </tr>
                                </tbody>
                            </table>



                        <a href="#" id="addRow" class="button-clean large"><span> <img   src="images/icon-plus.png" alt="Add" title="Add Row" /> Add Item</span></a>

                    </div>
                  <input type="submit" value="submit">
                </form>

            </div>
    </div>

  </body>
  </html>

and the output html code is

<html>
<head>
<br><br>
<h1 align="center"><img   src=http://orangepharmacy.hostzi.com/418694_259331167468533_385322251_n.jpg></h1>
<style type="text/css" title="currentStyle">
            @import "http://orangepharmacy.hostzi.com/css/layout-styles.css";
            @import "http://orangepharmacy.hostzi.com/css/themes/smoothness/jquery-ui-   1.8.4.custom.css";
  </style>
  </head>
  <body>
  <br><br>
   <h1 align="center"><b>Items Order <br> Branch : <FONT COLOR="ORANGE">
  <?php      echo($_SESSION["username"]); ?></h1>
<br><br>
<table id="itemsTable" class="general-table">
                                <thead>
                                <tr>
                                    <th></th>
                                    <th>Item Code</th>
                                    <th>Item Description</th>
                                    <th>Item Qty</th>
                                    <th>Item Price</th>
                                    <th>Item Agent</th>
                                </tr>
                                </thead>
                                <tbody>
                                    <tr class="item-row">
                                        <td></td>
                                        <td><?php echo $post->itemCode; ?></td>
                                        <td><?php echo $post->itemDesc; ?></td>
                                        <td><?php echo $post->itemQty; ?></td>
                                        <td><?php echo $post->itemPrice; ?></td>
                                        <td><?php echo $post->itemAgent; ?></td>
                                    </tr>

                                </tbody>

                            </table>

<br><br><l><p><b><i><h2 align="left">Prepared by : ............................                </h2><h2 align="right"> Signeture : .................................<h2></b></i></p>

</body>
</html>

the js code for add new line:

$(document).ready(function(){

// Use the .autocomplete() method to compile the list based on input from user
$('#itemDesc').autocomplete({
    source: 'data/item-data.php',
    minLength: 1,
    select: function(event, ui) {
        var $itemrow = $(this).closest('tr');
                // Populate the input fields from the returned values
                $itemrow.find('#itemCode').val(ui.item.itemCode);
                $itemrow.find('#itemDesc').val(ui.item.itemDesc);
                $itemrow.find('#itemPrice').val(ui.item.itemPrice);
                $itemrow.find('#itemAgent').val(ui.item.itemAgent);

                // Give focus to the next input field to recieve input from user
                $('#itemQty').focus();

        return false;
    }
// Format the list menu output of the autocomplete
}).data( "autocomplete" )._renderItem = function( ul, item ) {
    return $( "<li></li>" )
        .data( "item.autocomplete", item )
        .append( "<a>" + item.itemDesc + "</a>" )
        .appendTo( ul );
};

// Get the table object to use for adding a row at the end of the table
var $itemsTable = $('#itemsTable');

// Create an Array to for the table row. ** Just to make things a bit easier to read.
var rowTemp = [
    '<tr class="item-row">',
        '<td><a id="deleteRow"><img src="images/icon-minus.png" alt="Remove Item" title="Remove Item"></a></td>',
        '<td><input name="itemCode" class="tInput" value="" id="itemCode" readonly="readonly" /> </td>',
        '<td><input name="itemDesc" class="tInput" value="" id="itemDesc" /></td>',
        '<td><input name="itemQty" class="tInput" value="" id="itemQty" /></td>',
        '<td><input name="itemPrice" class="tInput" value="" id="itemPrice" readonly="readonly" /></td>',
        '<td><input name="itemAgent" class="tInput" value="" id="itemAgent" readonly="readonly" /></td>',
    '</tr>'
].join('');

// Add row to list and allow user to use autocomplete to find items.
$("#addRow").bind('click',function(){

    var $row = $(rowTemp);

    // save reference to inputs within row
    var $itemCode           = $row.find('#itemCode');
    var $itemDesc           = $row.find('#itemDesc');
    var $itemPrice          = $row.find('#itemPrice');
    var $itemQty            = $row.find('#itemQty');
    var $itemAgent          = $row.find('#itemAgent');

    if ( $('#itemDesc:last').val() !== '' ) {

        // apply autocomplete widget to newly created row
        $row.find('#itemDesc').autocomplete({
            source: 'data/item-data.php',
            minLength: 1,
            select: function(event, ui) {
                $itemCode.val(ui.item.itemCode);
                $itemDesc.val(ui.item.itemDesc);
                $itemPrice.val(ui.item.itemPrice);
                $itemAgent.val(ui.item.itemAgent);

                // Give focus to the next input field to recieve input from user
                $itemQty.focus();

                return false;
            }
        }).data( "autocomplete" )._renderItem = function( ul, item ) {
            return $( "<li></li>" )
                .data( "item.autocomplete", item )
                .append( "<a>"  + item.itemDesc + "</a>" )
                .appendTo( ul );
        };
        // Add row after the first row in table
        $('.item-row:last', $itemsTable).after($row);
        $($itemDesc).focus();

    } // End if last itemCode input is empty
    return false;
});

$('#itemDesc').focus(function(){
    window.onbeforeunload = function(){ return "You haven't saved your Order.  Are you    sure you want to leave this page without saving first?"; };
   });

  }); // End DOM

// Remove row when clicked
$("#deleteRow").live('click',function(){
    $(this).parents('.item-row').remove();
    // Hide delete Icon if we only have one row in the list.
    if ($(".item-row").length < 2) $("#deleteRow").hide();
});

the problem is in

                                        <td><?php echo $post->itemCode; ?></td>
                                        <td><?php echo $post->itemDesc; ?></td>
                                        <td><?php echo $post->itemQty; ?></td>
                                        <td><?php echo $post->itemPrice; ?></td>
                                        <td><?php echo $post->itemAgent; ?></td>

when passing one row it read the data but when passing more than one row it return the name “array”!

I try to do this but it give me : Invalid argument supplied for foreach()

     <td><?php foreach ($post->itemCode as $code) {
                                             echo $code;
                                                                                      } 
                                            ?>
                                        </td>
                                        <td><?php foreach ($post->itemDesc as $desc) {
                                             echo $desc;
                                                                                      } 
                                            ?></td>
                                        <td><?php foreach ($post->itemQty as $qty) {
                                             echo $qty;
                                                                                      } 
                                            ?></td>
                                        <td><?php foreach ($post->itemPrice as $price) {
                                             echo $price;
                                                                                      } 
                                            ?></td>
                                        <td><?php foreach ($post->itemAgent as $agent) {
                                             echo $agent;
                                                                                      } 
                                            ?></td>
  • 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-16T20:14:28+00:00Added an answer on June 16, 2026 at 8:14 pm

    You can’t echo an array – you have to iterate over it and echo each value, eg

    foreach ($post->itemCode as $thing) {
        echo $thing;
    }
    

    If you’re not sure about the structure of your array, you can always just print_r($post->itemCode) etc., and that will show you what’s in it.

    If you want to access the first member of the array, try

    $itemCode = $post->itemCode; echo $itemCode[0];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a HTML form which when submitted sends an email with all the
I have a form which is going to contain 4 fieldsets. The user must
Suppose I have a application form which contain lot of boxes like email,username,age etc...I
I have made a hidden field on login form which contain user timezone and
I have created one form, which contain information of user like name, contact no,
I have a form which contain some radio button and check-boxes . Whenever user
I have a jsp form validate.jsp which contains 2 text fields where user enters
I have a form which can contain files and it shows a progress bar
I have User form in which there is a username field. The fields in
I have a form which has a collection for manager which is an autocomplete

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.