Below is the field where user enters his/her email address and the AJAX post request is sent to the server and the user sees the message:
[PHP]echo("<div id=\"message\" class=\"success \">Thank you! You have been successfully registered.</div>");[/PHP]
within 1.5 seconds.
[PHP]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Testin g Homepage</title>
<link href="main.css" rel="stylesheet " type="text/css" media="screen" />
</head>
<body>
<script type="text/javascript" language="javas cript">
// Set path to PHP script
var phpscript = 'subscribe.php' ;
function createRequestOb ject() {
var req;
if(window.XMLHt tpRequest){
// Firefox, Safari, Opera...
req = new XMLHttpRequest( );
req.overrideMim eType('text/xml');
} else if(window.Activ eXObject) {
// Internet Explorer 5+
req = new ActiveXObject(" Microsoft.XMLHT TP");
} else {
// There is an error creating the object,
// just as an old browser is being used.
alert('There was a problem creating the XMLHttpRequest object');
}
return req;
}
// Make the XMLHttpRequest object
var http = createRequestOb ject();
function sendRequestPost (data) {
var emailPat = "^([0-9a-z]+)([0-9a-z._-]+)@([0-9a-z._-]+)\.([0-9a-z]+)";
var vemailid=docume nt.getElementBy Id('email1').va lue;
var matchArray = vemailid.match( emailPat);
if(document.get ElementById('em ail1').value == '')
{
alert("'Email Address' field can not be blank.");
document.getEle mentById('email 1').focus();
}
else if (matchArray == null)
{
alert("Your email address seems incorrect. Please try again.");
document.getEle mentById('email 1').focus();
}
else {
http.open('post ', phpscript, true);
http.setRequest Header('Content-Type', 'application/x-www-form-urlencoded');
http.setRequest Header("Connect ion", "close");
http.onreadysta techange = handleResponseP ost;
http.send('emai l1='+data);
}
}
function handleResponseP ost() {
if(http.readySt ate == 4 && http.status == 200){
var response = http.responseTe xt;
if(response) {
document.getEle mentById("dt"). innerHTML = response;
}
}
}
</script>
<div class="subscrib e">
<br />
Email Address: <input type="text" name="email1" id="email1" maxlength="36" size="36" />
<input type="button" name="go" value="Register " onclick="sendRe questPost(docum ent.getElementB yId('email1').v alue);" />
<div id="dt"></div>
</div>
</body>
[/PHP]</html>
This is subscribe.php:
[PHP]<?php
if(isset($_POST['email1'])){
$email = $_POST['email1'];
echo"<br>";
echo("<div id=\"message\" class=\"success \">Thank you! You have been successfully registered.</div>");
}
?>[/PHP]
Now my question is:
How to save text field data (i.e. the email address entered by the user) in a text file with multiple values separated by comma? Or in other case how to save these values in an Excel CSV file. We do not want these values to be stored in a database but just want a text file to be created on the first entered value and the rest of the values when entered second time or third time should be appended with the separation of comma i.e:
abc@abc.com,bbb @bbb.org.uk, ccccccccddd@efg hi.com
and like that.
Can any one help?
[PHP]echo("<div id=\"message\" class=\"success \">Thank you! You have been successfully registered.</div>");[/PHP]
within 1.5 seconds.
[PHP]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Testin g Homepage</title>
<link href="main.css" rel="stylesheet " type="text/css" media="screen" />
</head>
<body>
<script type="text/javascript" language="javas cript">
// Set path to PHP script
var phpscript = 'subscribe.php' ;
function createRequestOb ject() {
var req;
if(window.XMLHt tpRequest){
// Firefox, Safari, Opera...
req = new XMLHttpRequest( );
req.overrideMim eType('text/xml');
} else if(window.Activ eXObject) {
// Internet Explorer 5+
req = new ActiveXObject(" Microsoft.XMLHT TP");
} else {
// There is an error creating the object,
// just as an old browser is being used.
alert('There was a problem creating the XMLHttpRequest object');
}
return req;
}
// Make the XMLHttpRequest object
var http = createRequestOb ject();
function sendRequestPost (data) {
var emailPat = "^([0-9a-z]+)([0-9a-z._-]+)@([0-9a-z._-]+)\.([0-9a-z]+)";
var vemailid=docume nt.getElementBy Id('email1').va lue;
var matchArray = vemailid.match( emailPat);
if(document.get ElementById('em ail1').value == '')
{
alert("'Email Address' field can not be blank.");
document.getEle mentById('email 1').focus();
}
else if (matchArray == null)
{
alert("Your email address seems incorrect. Please try again.");
document.getEle mentById('email 1').focus();
}
else {
http.open('post ', phpscript, true);
http.setRequest Header('Content-Type', 'application/x-www-form-urlencoded');
http.setRequest Header("Connect ion", "close");
http.onreadysta techange = handleResponseP ost;
http.send('emai l1='+data);
}
}
function handleResponseP ost() {
if(http.readySt ate == 4 && http.status == 200){
var response = http.responseTe xt;
if(response) {
document.getEle mentById("dt"). innerHTML = response;
}
}
}
</script>
<div class="subscrib e">
<br />
Email Address: <input type="text" name="email1" id="email1" maxlength="36" size="36" />
<input type="button" name="go" value="Register " onclick="sendRe questPost(docum ent.getElementB yId('email1').v alue);" />
<div id="dt"></div>
</div>
</body>
[/PHP]</html>
This is subscribe.php:
[PHP]<?php
if(isset($_POST['email1'])){
$email = $_POST['email1'];
echo"<br>";
echo("<div id=\"message\" class=\"success \">Thank you! You have been successfully registered.</div>");
}
?>[/PHP]
Now my question is:
How to save text field data (i.e. the email address entered by the user) in a text file with multiple values separated by comma? Or in other case how to save these values in an Excel CSV file. We do not want these values to be stored in a database but just want a text file to be created on the first entered value and the rest of the values when entered second time or third time should be appended with the separation of comma i.e:
abc@abc.com,bbb @bbb.org.uk, ccccccccddd@efg hi.com
and like that.
Can any one help?
Comment