0

I am trying to build a very simple ordering form where people can pick from a hand full of products and also select a corresponding amount for each product.

<form id="order" method="post" action="" enctype="multipart/form-data">

  <table id="products">  
    <xsl:for-each select="/data/products/entry">
   <tr>
         <td>
           <xsl:value-of select="name"/>
         </td>
         <td>
           <label>Amount
             <input name="fields[{name}]" type="number" min="0" value="1" />
           </label>
       <input name="send-email[body]" value="fields[{name}]" type="hidden" />
     </td>
   </tr>
 </xsl:for-each>  
   </table>

   <label>Name
     <input name="fields[name]" type="text" />
   </label>

   <label>E-mail
     <input name="fields[e-mail]" type="text" />
   </label>

   <label>Address
     <input name="fields[address]" type="text" />
   </label>

   <input name="send-email[recipient]" value="tintin" type="hidden" />
   <input name="send-email[sender-email]" value="fields[e-mail]" type="hidden" />
   <input name="send-email[sender-name]" value="fields[name]" type="hidden" />  
   <input name="send-email[reply-to-email]" value="fields[e-mail]" type="hidden" />
   <input name="send-email[reply-to-name]" value="fields[name]" type="hidden" />
   <input name="send-email[subject]" value="An order has been placed" type="hidden" />
   <input name="action[order]" type="submit" value="Place order" />

</form>

The user data submitted through the form above should be converted to and sent as an email.

This works for the most part but how can I list the products the user ordered and their corresponding amounts?

I tried to solve this through a hidden form field inside the for-each loop. However, this will only send the name and amount of the last product in the list.

Thanks for any help!

Tintin81
  • 9,821
  • 20
  • 85
  • 178

1 Answers1

1

The Email method you're using is very basic indeed - I'd suggest you use something such as Email Template Manager which gives a much better overall result.. But in theory you'd need to save the data as array

<input name="fields[{name}][]" type="number" min="0" value="1" />
Jon Mifsud
  • 163
  • 2