You need to fill out an e-mail and submit.
The Javascript with an error is set to not run until you submit the form.
You need to fill out an e-mail and submit.
The Javascript with an error is set to not run until you submit the form.
There is an unexpected token? Here is the updated code, ryan
[code]$(â#subscribersâ).submit(function(event) {
event.preventDefault();
$("body").append("<div class=\"overlay\"><div class=\"loading-bar\"><span></span><span></span><span></span><span></span><span></span></div></div>");
$(".overlay").css("z-index","9999");
var email=$(".enter-information").val();
$(".enter-information").prop("disabled", true);
$.ajax({
type: "POST",
dataType: "text",
data: {
'subEmail': email
},
url: "scripts/process.php",
success: function(data) {
data = JSON.parse(data);
if(data.result[0])
{
$(".overlay").remove();
$("#subscribers").fadeTo(1000,0);
$("<p class=\"success-message\"><span>Success:</span> Thank you for subscribing. Please check your e-mail, <strong>"+data.result[1]+"</strong>, for the confirmation code.</p>").appendTo("#newsletter").delay(1500).fadeIn(1000);
}
else
{
$(".overlay").remove();
$(".enter-information").prop("disabled", false);
if(data.result[1]==="doubleentry")
{
$("<span id=\"attempts-error\" class=\"error\">Error: You are already subscribed</span>").appendTo("#subscribers");
}
else if(data.result[1]==="format")
{
$("<span class=\"error\">Error: Please enter a valid e-mail address</span>").appendTo("#subscribers");
}
$(".enter-information").removeClass("valid").addClass("error");
}
}
});
return false;
});
[/code]
BTW, what is json?
The console is telling me that line 16 is the issue, which is the data=JSON.parse(data).
Whatâs your process.php?
I highly doubt you changed your HTML to match that data I had in my Javascript. This is likely faulty data.
JavaScript Object Notation.
It is a common way of defining objects and properties in JavaScript that has also turned out to be a useful way to pass data between programming languages.
Yup I was right. Your name is still name=âEmailâ. Needs to have that updated. You updated the ID but thatâs not what PHP looks at. It looks at the name attribute when it looks at $_POST[âwhateverâ]. That âwhateverâ is whatever the name attribute holds.
Process.php is [code]if(isset($_POST[âsubEmailâ]))
{
$email=filter_input(INPUT_POST,âsubEmailâ);
$formData=new Subscribers($pdo);
$isValid=$formData->newSubscriber($email);
}
$isAjax = !empty($_SERVER[âHTTP_X_REQUESTED_WITHâ]) && strtolower($_SERVER[âHTTP_X_REQUESTED_WITHâ]) == âxmlhttprequestâ;
if($isAjax)
{
$result=[âresultâ => $isValid];
header(âContent-Type: application/jsonâ);
exit(json_encode($result));
}
if(isset($_POST[âsubscribeâ]))
{
if($isValid[0])
header(âLocation: http://www.reesecodes.come/index?result=subscribed&email=â.$isValid[1].â#newsletterâ);
else
header(âLocation: http://www.reesecodes.com/index?error=$isValid[1]#newsletterâ);
}
[/code]
so in post I have to change that value to Email?
Just change your HTML name to subEmail.
to what though, Iâm not sure what youâre talking about. Change name attribute of the input for email to subEmail?
Yes. That name=âsubEmailâ must be there. Not name=âEmailâ. That âEmailâ name is doing absolutely nothing right now. That name attribute must match the data that is being passed via jQuery.
And that must match the $_POST[âsubEmailâ] that is being sent. Easier to just update the HTML rather than the JS/PHP.
Ok, we got progress. Doesnât seem to be finishing out the code, you will see when you try it. I used your css file for now ryan. Also, fordata: {
'subEmail': email
},
in the javascript. This doesnât seem right, are you sure thatâs what it is supposed to be?
If thatâs what you are meaning to send along
Can you please remove that custom overlay stuff from my code? Really hampering from me being able to do stuff. Remove all aesthetics. We just need the base code working.
Also your PHP is just copy/pasted from mine. How do you expect it to return anything?! Your error logs on your server are probably filled with errors from faulty PHP.
I put in comments the entire contents of your miscellaneous css
Iâve already mentioned this is custom class/method code by me. You cannot possibly make use of it.
Okay, so do I delete that entire if statement and the bracket/ Your previous post of removing the if statement and closing brackets were aimed at the javascript originally
No, you remove those two lines. Just to get this working, we are going to assume all input is going to be true/valid.
So replace those two lines with âŚ
$isValid=array(true, "");
Itâll do for now.
FYI, in your PHP, youâll need to do something like this for false values (the second value I make there for the error message)
$isValid=array(false, "errorhere");
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.