So, I have a form with an input field and 3 types divthat are highlighted when clicked. I am trying to get it to send the attribute and the value "#email" and send it to me in PHP.
Here is 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 is 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 = "purchases@prismpc.net";
$subject = "Custom PC";
$email = $_POST['email'];
$storage = $_POST['storage'];
$entire = "Email: ".$email."\n"."Storage: ".$storage;
mail($emailto, $subject, $entire);
?>
However, when I see an email, that’s all I get:
Email:
Storage:
What am I doing wrong? Do I need to install dataType? Thank you so much for your answers!
Edit: different from a similar question because it was a simple syntax error.
source
share