私のアイデアは注文フォームを作成することです。私はフォームを作成し、私はクリックして、新しい製品を選択する新しいフィールドを作成したい場合は、フィールドの製品と数量をクローンするためにjavascriptを使いました。彼が望む多くの製品を選択することができます。問題は、PHPを使ってクローンされたこの情報を電子メールに送る方法を知らないことです。 私のコードは次のとおりクローンアイテムをPHPのjavascriptで送信する
function addInput(divName) {
var copy = document.getElementById('forclone').cloneNode(true);
document.getElementById(divName).appendChild(copy);
}
<form method="post" id="onlineorder" action="sendform.php">
<fieldset id="listproducts">
<legend>PRODUCTS</legend>
<div id='forclone'>
<select name="product" id="product">
<optgroup label="PRODUCT 1">
<option>PRODUCT 1 - BLUE</option>
<option>PRODUCT 1 - RED</option>
<option>PRODUCT 1 - YELLOW</option>
</optgroup>
<optgroup label="PRODUCT 2">
<option>PRODUCT 2 - WHITE</option>
<option>PRODUCT 2 - BLACK</option>
<option>PRODUCT 2 - GRAY</option>
</optgroup>
</select>
<label for="quantity">Quantity:<span style="color:red">*</span>
</label>
<input type="number" name="quantity" id="quantity" placeholder="Qnt" min="0" max="9999" required/>
</div>
<div id="dynamicinput"></div>
<input type="button" value="New Product" onclick="addInput('dynamicinput');" />
</fieldset>
<p></p>
<input type="submit" value="SUBMIT">
</form>
PHP(sendform.php)
<?php
if(isset($_POST['email'])) {
$email_to = "[email protected]";
$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._%-][email protected][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
}
?>
のような配列として選択したタグのname属性を指定しますあなたはその配列を読むことができます... – RohitS
私は申し訳ありませんが、私は新しい、より具体的になることができますか? – Evandro
ちょっと...私の意味はあなたのHTML要素にあなたのselect要素が "product []"と書かれていて、phpで配列として読み取ることができます。 .. [私はサンプルを追加します] – RohitS