Okay…im trying to have a textarea save to text file using php, but I also need it to use a javascript pop up box to validate that information has been entered. I can’t get both to work at the same time! Code is below…Any help on this would be greatly appreciated.
<html>
<head>
<link rel="stylesheet"
type="text/css" href="style.css"/>
<script type="text/javascript">
<!-- <!CDATA[
function validateForm()
{
var x=document.forms["myForm"]["email"].value;
var atpos=x.indexOf("@");
var dotpos=x.lastIndexOf(".");
if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length)
{
alert("Not a valid e-mail address");
return false;
}
}
// ]]> -->
</script>
</head>
<form name="form1" method="post" action="index2.php?saving=1">
<textarea name="data" cols="100" rows="10">
Username:
Password:
---------------------------------------------
</textarea>
<br>
</form>
<form name="myForm" method ="post" action="index2.php?saving=1" onsubmit="return validateForm();">
<tr>
<td align="right" width="10%"> Email: </td>
<td><input type="text" name="email" id="email" size ="40" />
</td>
</tr>
<input type="submit" value="Submit">
</form>
<p>
<a href="index.html">Home</a>
</html>
[php]
<?php $saving = $_REQUEST['saving']; if ($saving == 1){ $data = $_POST['data']; $file = "data.txt"; $fp = fopen($file, "a") or die("Couldn't open $file for writing!"); fwrite($fp, $data) or die("Couldn't write values to file!"); fclose($fp); echo "Saved to $file successfully!"; } ?>[/php]