OK, so here is my slightly complicated question for you guys.
I have a WordPress site where user can add products to category, there is functionality which displays sorted products in one page. Here is pretty much code of single product:
<td><input class="cbx" type="checkbox" name="product" value="product"> </td>
<td class="bright"><?php the_title(); ?> <input class="ptitle" type="hidden" name="ptitle" value="<?php the_title(); ?>"></td>
<td class="bright">box</td>
<td class="bright">height</td>
<td class="bright">price</td>
<td> <input class="count" type="text" name="<?php echo $post->ID; ?>count" maxlength="4"></td>
</tr>
This code is looped and displays in form tags on other archive.php . On archive.php i have jquery script which sends data from form to mail.php pasted below (i stripped it a bit for better visibility):
<?php
// Fetching Values from URL.
$email = $_POST['email'];
$place = $_POST['place'] ;
$street = $_POST['street'] ;
$code = $_POST['code'] ;
$email = filter_var($email, FILTER_SANITIZE_EMAIL);
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
$subject = 'new message';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From:' . $email. "\r\n";
$template = '<div><br><b>Adress:</b><br> '.$street.'<br>'. $code.' '.$place.'<br>'. '<br><b>Email:</b> ' . $email . '<br>'
$sendmessage = "<div>" . $template . "</div>";
$sendmessage = wordwrap($sendmessage, 70);
mail("test@test.com", $subject, $sendmessage, $headers);
echo "success.";
} else {
echo "<span>*incorrect email*</span>";
}
What i need is a function which will check if product is checked, get its name, gets number which is provided through input and sends it through my email function.
I have no problem sending predefined inputs, but when i get some dynamic data (there are multiple products), i don't know how to handle this. All i have in mind is creating array and foreach loop.
I will appreciate any tips how to deal with this :)
Aucun commentaire:
Enregistrer un commentaire