Cant use submit button
Posted: Sun Oct 16, 2011 3:37 pm
I am not able to make the following php code work for me. I can not use a submit button and need to use javascript to submit the form.
Anyone who can help and tell me what is wrong?
<?php
if(isset($_REQUEST['submit'])) {
$content = time();
$fi = "nettotest.txt";
$fh = fopen($fi, 'w') or die("can't open file (48) - dot info");
fwrite($fh, $content);
fclose($fh);
} else {
echo " <!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01//EN'
'http://www.w3.org/TR/html4/strict.dtd'>
<html dir='ltr' xml:lang='en' lang='en'>
<head>
<meta http-equiv='Content-Type' content='text/html'; charset='utf8' />
<script type='text/javascript'>
function submitForm() {
document.forms['myForm'].submit();
}
</script>
</head>
<body>";
printf("<form id='myForm' name='myForm' method='POST' action='%s'>", $_SERVER["PHP_SELF"]);
echo "
<table>";
echo "
<tr>
<td colspan='4'>";
$fi = "nettotest.txt";
if (file_exists($fi)) {
echo readfile("nettotest.txt");
}
else {
echo "file do not exist";
}
echo "</td>
</tr>
";
// -----------------------------------
/*
echo "
<tr>
<td colspan='3'>
<a href='javascript: submitForm()'>Search</a>
</td>
</tr>
";
*/
// -----------------------------------
echo "<tr><td colspan='3'>
<input type='button' id='registrer' name='registrer' tabIndex='38' value='submit' onclick='submitForm()' />
";
// -----------------------------------
/*
echo "<tr><td colspan='3'>
<input type='Submit' value='Submit' />
</td></tr> ";
*/
// -----------------------------------
echo "</table>
</form>
</body>";
}
?>
Anyone who can help and tell me what is wrong?
<?php
if(isset($_REQUEST['submit'])) {
$content = time();
$fi = "nettotest.txt";
$fh = fopen($fi, 'w') or die("can't open file (48) - dot info");
fwrite($fh, $content);
fclose($fh);
} else {
echo " <!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01//EN'
'http://www.w3.org/TR/html4/strict.dtd'>
<html dir='ltr' xml:lang='en' lang='en'>
<head>
<meta http-equiv='Content-Type' content='text/html'; charset='utf8' />
<script type='text/javascript'>
function submitForm() {
document.forms['myForm'].submit();
}
</script>
</head>
<body>";
printf("<form id='myForm' name='myForm' method='POST' action='%s'>", $_SERVER["PHP_SELF"]);
echo "
<table>";
echo "
<tr>
<td colspan='4'>";
$fi = "nettotest.txt";
if (file_exists($fi)) {
echo readfile("nettotest.txt");
}
else {
echo "file do not exist";
}
echo "</td>
</tr>
";
// -----------------------------------
/*
echo "
<tr>
<td colspan='3'>
<a href='javascript: submitForm()'>Search</a>
</td>
</tr>
";
*/
// -----------------------------------
echo "<tr><td colspan='3'>
<input type='button' id='registrer' name='registrer' tabIndex='38' value='submit' onclick='submitForm()' />
";
// -----------------------------------
/*
echo "<tr><td colspan='3'>
<input type='Submit' value='Submit' />
</td></tr> ";
*/
// -----------------------------------
echo "</table>
</form>
</body>";
}
?>