How to stop form from generating new page
Posted: Mon Dec 14, 2009 9:29 am
This is xHTML / php code to grab a few fields and write them to a "|" delimited file for later import into an Excel/OO spreadsheet.
The problem is that the mailer.php below generates a new page and messes things up. I would like to place an <alert> to inform the user that his message has been sent. I would also like to clear the form (already done) and stay or reload the original page (code listed above). Any suggestions, ideas would be welcome.
Code: Select all
<div id="stylized" class="myform">
<form id="form" action="mailer.php?savedata=1" method="post">
<fieldset>
<h1>Tell us about yourself!</h1>
<label>Name</label><input type="text" name="name" id="name" maxlength="25" />
<label>Email</label><input type="text" name="email" id="email" maxlength="25" />
<label>Country</label><input type="text" name="country" id="country" />
<label>Rating</label><input type="text" name="rating" id="rating" size="5" />
<br class="clear" />
List chess goals and other pertinent information:<br />
<textarea name="message" rows="5" cols="60"></textarea><br />
<input type="submit" name="submit" value="Submit" />
<input type="reset" value="Reset" name="reset" />
</fieldset>
</form>
</div>
Code: Select all
<?php
$savedata = $_REQUEST['savedata'];
if ($savedata == 1){
$data = date("ymdHis");
$data .= "|";
$data .= $_POST['name'];
$data .= "|";
$data .= $_POST['email'];
$data .= "|";
$data .= $_POST['country'];
$data .= "|";
$data .= $_POST['rating'];
$data .= "|";
$data .= $_POST['message'];
$data .= "\n";
$file = "./datafile.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);
}
?>