Insert e-mails to a text file
I have a "Coming soon" page but I want to add an "insert your e-mail" option and the e-mai开发者_JS百科l to be inserted on a CSV or text file. What I have is an AJAX validate e-mail address and the input field:
function isValidEmailAddress(emailAddress) {
var pattern = new RegExp(/^(("[w-s]+")|([w-]+(?:.[w-]+)*)|("[w-s]+")([w-]+(?:.[w-]+)*))(@((?:[w-]+.)*w[w-]{0,66}).([a-z]{2,6}(?:.[a-z]{2})?)$)|(@[?((25[0-5].|2[0-4][0-9].|1[0-9]{2}.|[0-9]{1,2}.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2}).){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})]?$)/i);
return pattern.test(emailAddress);
}
/*FORM validation and div changing*/
$(document).ready(function() {
$().click(function (ev) {
var $target = $(ev.target);
if( !$target.is("input") ) {
$("input#email").val('Vendosni e-mail tuaj qe tju njoftojme per hapjen e faqes');
}
});
$("#email").click(function() {
$("input#email").val('');
});
$("#submit").click(function() {
var email = $("input#email").val();
if(!isValidEmailAddress(email)){
$("input#email").focus();
$("input#email").val('Vendosni nje e-mail te sakte');
return false;
}
});
/*form submit*/
$("form#form-email").submit(function() {
var email = $("input#email").val();
$.ajax({
url:'mail.php',
type:'post',
data: "email="+email,
success: function(msg){
if (msg==1)
$("input#email").val('Ju faleminderit! Deshironi te regjistroni nje e-mail tjeter ?');
else
$("input#email").val('Gabim! Ndodhi nje gabim ne dergim!');
}
});
return false;
});
/*end formsubmit*/
});
<form action="mail.php" method="post" id="form-email">
<p>
<input type="text" name="email" id="email" value="Vendosni e-mail tuaj qe tju njoftojme per hapjen e faqes"/>
</p>
<p>
<input type="submit" name="submit" id="submit" value="" />
</p>
</form>
very basic mail.php pointing to file called 'email.txt'
<?php
$file = fopen('email.txt', 'a');
fwrite($file, $_POST['email'] . "\n");
fclose($file);
?>
精彩评论