- Messages
- 4,148
- Reaction score
- 5
- Points
- 38
I have written a script that you fill in a form and then submit it but am having a little trouble with it. Also need feeback and sugestions if you wouldn't mind.
http://www.defectalisman.com/examples/form.php
It uses basic php, html & javascript.
It submits to $PHP_SELF.
The prob I am having is that if you refresh the page and then fill in all the requiered feilds (put a return at the end of the comments box ) and press enter on another feild it skips the javascript and there after (without a refresh) even pressing the preveiw button does the same?
This is the code for the script.
Like I said any feedback as a better way to do something please post.
P.S. Also it seems to take a while to process the form ? ? ?
http://www.defectalisman.com/examples/form.php
It uses basic php, html & javascript.
It submits to $PHP_SELF.
The prob I am having is that if you refresh the page and then fill in all the requiered feilds (put a return at the end of the comments box ) and press enter on another feild it skips the javascript and there after (without a refresh) even pressing the preveiw button does the same?
This is the code for the script.
PHP:
<?php
// Change to 1 to make it test itself
$test = 0;
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Mail Form - DefecTalisman</title>
<style type="text/css">
<!--
.style1 {font-size: 9px}
-->
</style>
<script type="text/javascript" language="javascript" src="req.js">
</script>
</head>
<?php
if (!isset($_POST['preview']))
{
?>
<body>
<p align="center">Basic Form that checks itself. </p>
<form method="post" action="<?php echo $PHP_SELF; ?>">
<table width="640" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td>Your Name :</td>
<td><input type="text" size="50" maxlength="100" name="usr_name" />
* </td>
</tr>
<tr>
<td>Your e-mail Address : </td>
<td><input type="text" size="50" maxlength="100" name="usr_mail" />
*</td>
</tr>
<tr>
<td>Subject : </td>
<td><input type="text" size="50" maxlength="100" name="subject" />
*</td>
</tr>
<tr>
<td>Type Of Message : </td>
<td><select name="msg_type">
<option value='' ="selected">Please Select A Catagory</option>
<option value="support">Support</option>
<option value="c_care">Customer Care</option>
</select>
*</td>
</tr>
<tr>
<td colspan="2"><div align="center">Comments *
<br />
<textarea rows="5" cols="50" name="comments" wrap="physical"></textarea>
</div></td>
</tr>
<tr>
<td>Other : </td>
<td><input type="text" size="50" maxlength="100" name="other" /></td>
</tr>
<tr>
<td colspan="2"><div align="center">
<input type="submit" value="Preview" name="preview" onKeyPress="history.go(-1)"/>
<input type="reset" value="Default" />
<input type ="button" value="Back" name ="back" onClick="history.go(-1)" />
</div></td>
</tr>
</table>
</form>
</body>
<?php
}
?>
<?php
/*
* This is where the form gets procesed if the preview button was pressed
*/
if (isset($_POST['preview']))
{
// Enter the required feilds into the array along with their scrren names
$reqired_fields = array(
'usr_name' => 'Your Name',
'usr_mail' => 'Your e-mail Address',
'subject' => 'Subject',
'msg_type' => 'Type Of Message',
'comments' => 'Comments'
);
$null_fields = array();
// This checks the feilds and then collects their screen names
foreach ($reqired_fields as $a => $z)
{
if (isset($_POST["$a"]))
{
if ($_POST[$a] == FALSE) { array_push($null_fields,$z); }
}
}
// If there are missing feilds then pop up and alert which ones, then go back 1
if ($null_fields == TRUE)
{
// BREAK for JavaScript
?>
<script language="JavaScript" type="text/javascript">
reqPopUP("<?php foreach ($null_fields as $t) { echo '\n*'.$t ; } ?>");
</script>
<?php
}
// If the required feilds are present
if ($null_fields == FALSE)
{
// Set them to a scalars
$to = 'defectalisman@hotmail.com';
$usr_name = $_POST['usr_name'];
$usr_add = $_POST['usr_mail'];
$type = $_POST['msg_type'];
$sub = $_POST['subject'];
$msg = $_POST['comments'];
// Set any other feilds from the form to scalars
if ($_POST['other'] == TRUE) { $other = $_POST['other']; } else { $other = 'Nothing'; }
// Set an array for pop up
$form_output = array();
array_push($form_output, $usr_name, $usr_add, $type, $sub, $msg, $other);
// BREAK for JavaScript
?>
<script language="JavaScript" type="text/javascript">
goodPopUP("<?php foreach ($form_output as $t) { echo '\n-'.$t ; } ?>");
</script>
<?php
// Now here we can work with the data (maybe call a php function)
echo 'All seems fine now its got to do something with the data.<br>';
echo '<input type ="button" value="Back" name ="back" onclick="history.go(-2)" />';
}
}
?>
</form>
</body>
</html>
Like I said any feedback as a better way to do something please post.
P.S. Also it seems to take a while to process the form ? ? ?
Last edited: