Jump to content

Subscribe form no longer posts input data


Marlon

Recommended Posts

I have a 'subscribe' form on a website that uses Ajax to validate the input fields, the form is then processed via php. The actual html code resides on a Wordpress page.

 

I had actually just got the form to work again. The website was static, and I transferred everything over to Wordpress, and the form didnt work. I was able to get it working by specifying the url: in ajax, as an absolute path to my php form. Overnight, something, I'm not sure what, stopped the form from processing. No data is posted to myql, and no email is sent or received. The status message just hangs at "Please wait while we process your information..." This message is in part of my Ajax code, so I am thinking something is wrong with my php script. I have a 'contact' page that uses nearly identical code that the 'subscribe' pages uses to validate the input fields, and it works.

 

I was able to recover both the ajax and php script from an earlier time when they did work, I uploaded back to my server and nothing, the form still does not process. I also made sure my database credentials were correct with my host, and even tested my connection to mysql which I was able to connect. Next, I made sure I was able to send mail with my host.

 

don't know what is causing the form to hang, and I would love to get this solved; any help would be appreciated!

 

PHP code:

 

<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {


define('DB_NAME', '######');
define('DB_USER', '######');
define('DB_PASSWORD', '######');
define('DB_HOST', '######');


$first = Trim(stripslashes($_POST['First']));
$last = Trim(stripslashes($_POST['Last']));
$city = Trim(stripslashes($_POST['City']));
$state = Trim(stripslashes($_POST['State']));
$country = Trim(stripslashes($_POST['Country']));
$email = Trim(stripslashes($_POST['Email']));
$tempt = $_POST['tempt'];
$tempt2 = $_POST['tempt2'];




if ($tempt == 'http://' && empty($tempt2)) {


$error_message = '';
$reg_exp = "/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9­-]+\.[a-zA-Z.]{2,5}$/";


if(!preg_match($reg_exp, $email)) {


$error_message .= "<p>A valid email address is required.</p>";
}
if (empty($first)) {
$error_message .= "<p>Please provide your first name.</p>";
}
if (empty($last)) {
$error_message .= "<p>Please provide your last name.</p>";
}


if (!empty($error_message)) {


$return['error'] = true;
$return['msg'] = "<p>The request was successful, but the form was not filled out correctly.</p>".$error_message;
echo json_encode($return);
exit();


$dbc = mysql_connect('######', '######', '######');
$check_email_for_duplicates = mysql_query($dbc, "select * from 'members' where 'Email' = '".mysql_real_escape_string($email)."'");
    if(mysql_num_rows($check_email_for_duplicates) > 0) //Email address is unique within this system and must not be more than one
    {
        echo 'Sorry, <b>'.$email.'</b> has already subscribed.';
    }


} else {


$return['error'] = false;
$return['msg'] = "<p style='top:12px; color:#ff6000; left:15px; text-align:left; font-size:1.50em;'>".$first .", <p style='top:0px; width:100%; left:15px; text-align:left; line-height:1.1em;'>your subscription request has been processed.</p>";
echo json_encode($return);
}


} else {


$return['error'] = true;
$return['msg'] = "<p>There was a problem while sending this form. Try it again.</p>";
echo json_encode($return);
}




$to = "######, ######";
$subject = "New Email Address for Mailing List";
$headers = "From: $email\n";
$headers .= "Content-type: text/html\r\n";


$message = "<span style='color:#252525; font-size:1.2em;'>A visitor to 3Elements Review has entered the following information so they can be added to your mailing list.</span><br>\n
<br>
<span style='color:#252525; font-weight:bold; font-size:1.35em;'>$first $last</span><br>
<span style='color:#252525; font-weight:bold; font-size:1.35em;'>$city, $state</span><br>
<span style='color:#252525; font-weight:bold; font-size:1.35em;'>$country</span><br>
<span style='color:#252525; font-weight:bold; font-size:1.35em;'>$email</span>";
mail($to,$subject,$message,$headers);








$user = "$email";
$usersubject = "Thank you for subscribing to 3Elements Review";
$userheaders = "From: ######\n";
$userheaders .= "Content-type: text/html\r\n";
$usermessage = "<body style='background-color:#dbf7ff; width:100%; height:105%;'>


<span style='color:#353535; font-size:2em; font-weight:bold; font-family:pt sans;'>Welcome</span> <span style='color:#ff6000; font-size:2em; font-weight:bold; font-family:pt sans;'>$first</span><span style='color:#353535; font-size:2em; font-weight:bold; font-family:pt sans;'>,</span><br>
<br>
<span style='color:#353535; font-size:1.30em; font-family:noto serif;'>We're glad that you've decided to subscribe to our email list. We adore the people of $city!</span><br>
<br>
<span style='color:#353535; font-size:1.30em; font-family:noto serif;'>We have a lot of great things in the works that we're excited about at <em>3Elements Review,</em> and we can't wait to show <em>you</em> and all of the other writers, artists, and photographers immersed in the $city literary scene, all that <strong><em>3Elements Review</em></strong> has in store!</span><br>
<br>
<span style='color:#353535; font-size:1.30em; font-family:noto serif;'>Stay tuned for information regarding our issue release dates, contests, and other news!<br>
<br>
If you find us interesting enough, like us on Facebook and follow us on Twitter!</span><br>
<br>
<br>
<span style='color:#353535; font-size:1.30em; font-family:noto serif;'>Sincerely,</span><br>
<br>
<span style='color:#ff6000; font-size:1.50em; font-family:pt sans;'>The 3Elements Team</span><br>
<br>
<br>
<p>


<span style='color:#353535; font-size:1.25em; font-family:pt sans; font-weight:bold;'>######</span><br>
<span style='color:#353535; font-size:1.25em; font-family:pt sans; font-weight:bold;'>######</span><br>
<span style='color:#ff6000; font-size:1.25em; font-family:pt sans; font-weight:bold;'>######</span><br>


<img src='http://www.3elementsreview.com/images/logo-2.svg' width='122px' height='95px'>
<br>
<p>
<span style='color:#353535; font-size:.9em; font-family:noto serif;'>You're receiving this email because you or someone you know subscribed you to our email list.</p>
<span style='color:#353535; font-size:.9em; font-family:noto serif;'>If you would rather not receive email from 3Elements Review, you can unsubscribe by clicking <a href='mailto:######?Subject=Unsubscribe%20Request'>here</a>.</p>
<br>
<p>
</body>";


mail($user,$usersubject,$usermessage,$userheaders);








$link = mysql_connect('######', '######', '######');


if (!$link) {
die('Could not connect: ' . mysql_error());
}


$db_selected = mysql_select_db('######', $link);


if (!$db_selected) {
die('Can\'t use ' . '######' . ': ' . mysql_error());
}


$value = mysql_real_escape_string($_POST['First']);
$value2 = mysql_real_escape_string($_POST['Last']);
$value3 = mysql_real_escape_string($_POST['City']);
$value4 = mysql_real_escape_string($_POST['State']);
$value5 = mysql_real_escape_string($_POST['Country']);
$value6 = mysql_real_escape_string($_POST['Email']);


$sql = "INSERT INTO members (First, Last, City, State, Country, Email, Date) VALUES('$value','$value2','$value3','$value4','$value5','$value6',NOW() + interval 2 hour)";


if (!mysql_query($sql)){
die('Error: ' . mysql_error());
}


mysql_close();


}else{}
?>

Ajax code:

//*************************************************************REQUIRED FIELD SCRIPT FOR SUBSCRIBE PAGE*************************************************//
$(document).ready(function() {
$('form #response2').hide();




$('.button2').click(function(e) {


e.preventDefault();


var valid = '';
var required = ' is required';
var first = $('form #first').val();
var last = $('form #last').val();
var email = $('form #email').val();
var tempt = $('form #tempt').val();
var tempt2 = $('form #tempt2').val();


if (first = '' || first.length <= 1) {
valid += '<p>Your first name' + required + '</p>';
}


if (last = '' || last.length <= 1) {
valid += '<p>Your last name' + required + '</p>';
}


if (!email.match(/^([a-z0-9._-]+@[a-z0-9._-]+\.[a-z]{2,4}$)/i)) {
valid += '<p>Your e-mail address' + required + '</p>';
}


if (tempt != 'http://') {
valid += '<p>We can\'t allow spam bots.</p>';
}


if (tempt2 != '') {
valid += '<p>A human user' + required + '</p>';
}


if (valid != '') {
$('form #response2').removeClass().addClass('error2')
.html('' +valid).fadeIn('fast');
}


else {
$('form #response2').removeClass().addClass('processing2').html('<p style="top:0px; left:0px; text-align:center; line-height:1.5em;">Please wait while we process your information...</p>').fadeIn('fast');


var formData = $('form').serialize();
submitForm(formData);
}


});


});


function submitForm(formData) {


$.ajax({


type: 'POST',
url: 'http://3elementsreview.com/blog/wp-content/themes/3elements/php-signup/sign-up-complete.php',
data: formData,
dataType: 'json',
cache: false,
timeout: 4000,
success: function(data) {


$('form #response2').removeClass().addClass((data.error === true) ? 'error2' : 'success2')
.html(data.msg).fadeIn('fast');


if ($('form #response2').hasClass('success2')) {
setTimeout("$('form #response2').fadeOut('fast')", 6000);
}


},
error: function(XMLHttpRequest, textStatus, errorThrown) {


$('form #response2').removeClass().addClass('error2')
.html('<p>There was an <strong>' + errorThrown +
'</strong> error due to an <strong>' + textStatus +
'</strong> condition.</p>').fadeIn('fast');
},
complete: function(XMLHttpRequest, status) {


$('form')[0].reset();
}


 });


};

 

Edited by Marlon
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.