evandrosx
-
Total de itens
2 -
Registro em
-
Última visita
Posts postados por evandrosx
-
-
Boa Noite,
Estou criando um formulário de pedido. Nesse formulário tem um campo com o produto e a quantidade. Eu estou utilizando uma função javascript para clonar o campo quando o cliente quer mais um produto, com isso cada vez que o cliente clica em novo produto cria uma nova caixa de seleção para ele selecionar o produto desejado e depois preenche a quantidade.
O que eu preciso é enviar esses dados que são gerados atraves dessa função por php. Tentei varias coisas mas em nenhuma obtive sucesso.
Segue abaixo os codigos.
Javascript
var runningproducttally = 1; function addInput(divName) { var copy = document.getElementById('forclone').cloneNode(true); var select1 = copy.getElementsByTagName('select')[0]; select1.setAttribute("name","product"+runningproducttally); document.getElementById(divName).appendChild(copy); runningproducttally++; }
PHP
<?php if(isset($_POST['email'])) { $email_to = "email@domain.com"; $email_subject = "[ Online Order ]"; function died($error) { echo "We are very sorry, but there were error(s) found with the form you submitted. "; echo "These errors appear below.<br /><br />"; echo $error."<br /><br />"; echo "Please go back and fix these errors.<br /><br />"; die(); } if(!isset($_POST['name']) || !isset($_POST['business']) || !isset($_POST['email']) || !isset($_POST['phone']) || !isset($_POST['quantity']) || !isset($_POST['product'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } $name = $_POST['name']; // required $business = $_POST['business']; // required $email_from = $_POST['email']; // required $phone = $_POST['phone']; // not required $quantity = $_POST['quantity']; // required $product = $_POST['product']; // not required $error_message = ""; $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; if(!preg_match($email_exp,$email_from)) { $error_message .= 'The Email Address you entered does not appear to be valid.<br />'; } if(strlen($error_message) > 0) { died($error_message); } $email_message = "<strong>You received an online order. <br>Follow below the informations.</strong><br><br>\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "<br><strong>Name: </strong>".clean_string($name)."\n"; $email_message .= "<br><strong>Business: </strong>".clean_string($business)."\n"; $email_message .= "<br><strong>Email: </strong>".clean_string($email_from)."\n"; $email_message .= "<br><strong>Phone: </strong>".clean_string($phone)."\n"; $email_message .= "<br><br><strong>ORDER: </strong>\n"; $email_message .= "<br><br><strong>Qty: </strong>".clean_string($quantity)."\n"; $email_message .= " <strong>Product: </strong>".clean_string($product)."\n"; $headers = "Content-Type: text/html; charset= UTF-8 \r\n"; $headers .= 'From: '.$email_from."\r\n". 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); ?> <p>Thank you for order. We will contact you as soon as possible.</p> <p>You can close this page now.</p> <?php } ?>
HTML
<fieldset id="listproducts"> <legend> PRODUCTS </legend> <div id = 'forclone'> <select name="product" id="product"> <optgroup label="GALLON BAG"> <option>GALLON BAG BANANA SPLIT</option> <option>GALLON BAG BIRTHDAY CAKE</option> <option>GALLON BAG COTTON CANDY</option> </optgroup> <optgroup label="PRE-CUP"> <option>PRE-CUP BANANA SPLIT</option> <option>PRE-CUP CHOCOLATE</option> <option>PRE-CUP COTTON CANDY</option> </optgroup> </select> <select name="quantity" id="quantity"> <optgroup label="Qty"> <option>1</option> <option>2</option> <option>3</option> <option>4</option> </optgroup> </select>
Enviar arquivos clonados em javascript usando php
em PHP
Postado
lowys, segue abaixo o formulario em html.