Have an account? Sign in
Login  Register  Facebook
Insert e-mails to a txt file
Hello there!
I have a "Coming soon" page but i want to add an "insert your e-mail" option and the e-mail to be inserted on a csv or txt 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>

Hope that you can help me on this.

Thanks in advance!
Started: September 19, 2011 Latest Activity: June 2, 2018 txt ajax csv jquery
2 Answers
Online Viagra Store <a href=http://brandciali.com>cialis 5mg</a> Mejor Tuenti Para Tomar Propecia Achat Kamagra Pharmacie Suisse

Posted: Ellgaibra
In: June 2, 2018

very basic mail.php pointing to file called 'email.txt'
if(isset($_POST['email'])){
    $file = fopen('email.txt', 'a');
        fwrite($file, $_POST['email'] . "\n");
    fclose($file);   
}

Posted: MacOS
In: September 19, 2011

Your Answer

xDo you want to answer this question? Please login or create an account to post your answer