So I have a form with an input box and an 3 of a type of div
that highlights when clicked. I'm trying to get it to submit the attribute and "#email" value and email it to me via PHP.
Here's my HTML:
<form id="form" name="form" class="custompurchase" action="custom.php" method="post">
<input type="email" id="email" name="email" maxlength="40" class="textbox2" placeholder="Email address" required/>
<a class="customoption storage" onclick="activate(this, 'storage');" data-name="500GB HDD">
...
</a>
<a class="customoption storage" onclick="activate(this, 'storage');" data-name="1TB HDD">
...
</a>
<a class="customoption storage" onclick="activate(this, 'storage');" data-name="2TB HDD">
...
</a>
</form>
Here's my JQuery:
$(function() {
var form = $('#form');
$(form).submit(function(event) {
event.preventDefault();
var email = $("#email").val();
var storage = $(".customoptionactive.storage").attr("data-name");
$.ajax({
type: "POST",
url: $(form).attr("action"),
data: email, storage
})
.done(function(response) {
...
});
});
});
And finally my PHP:
<?php
$emailto = "[email protected]";
$subject = "Custom PC";
$email = $_POST['email'];
$storage = $_POST['storage'];
$entire = "Email: ".$email."\n"."Storage: ".$storage;
mail($emailto, $subject, $entire);
?>
However, when I see the email, this is all I get:
Email:
Storage:
What am I doing wrong? Do I need to set the dataType
? Thank you so much for your answers!
Edit: Different from similar question because it was a simple syntax error.
Change your data
option on your $.ajax
data: email, storage
to
data: {email:email, storage:storage}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With