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>";
}
?>
Cant use submit button
Moderator: General Moderators
Re: Cant use submit button
They all work fine and your code is posting correctly, however you're not defining the HTML elements [name] correctly so the post action does not get processed.
You don't specify any HTML element with the name="submit"
The above says make my element an input of type submit with the text in the button of "Submit" - adding name="submit" will solve the problem.
Code: Select all
if(isset($_REQUEST['submit'])) {Code: Select all
<input type='Submit' value='Submit' />Re: Cant use submit button
Thanks for the answer, but I can not use a standard submit button as it tis activated in another javascript function when it is not supposed to.
I need to get a javascript to submit the form like:
<a href='javascript: submitForm()'>Submit</a>
OR
<input type='button' id='submit' name='submit' value='submit' onclick='javascript: submitForm()' />
<script type='text/javascript'>
function submitForm() {
document.forms['myForm'].submit('submit');
}
</script>
I do need help here as I am gone blind for the solution here.
I need to get a javascript to submit the form like:
<a href='javascript: submitForm()'>Submit</a>
OR
<input type='button' id='submit' name='submit' value='submit' onclick='javascript: submitForm()' />
<script type='text/javascript'>
function submitForm() {
document.forms['myForm'].submit('submit');
}
</script>
I do need help here as I am gone blind for the solution here.
Re: Cant use submit button
Code: Select all
function submitForm(){
document.forms.myform.submit();
}Code: Select all
<input type="hidedn" name="subsmit" value="submit"/>Re: Cant use submit button
If your form has an input element named 'submit', then your javascript code document.myform.submit() will suddenly refer to the input element, rather than the form's submit() method. And no way to explicitly specify which you mean.
This sort of ambiguity crap is one of the many reasons why I hate javascript
Anyway, solution: if your 'submit' input is a button, instead of yourform.submit() use yourform.submit.click();
If 'submit' is something else (e.g. a text input or something), add an invisible dummy button with some unique name or id, and call click() on that.
So if you have a form like this:
Then document.myform.submit() won't work, but document.getElementById('blahh').click() will.
This sort of ambiguity crap is one of the many reasons why I hate javascript
Anyway, solution: if your 'submit' input is a button, instead of yourform.submit() use yourform.submit.click();
If 'submit' is something else (e.g. a text input or something), add an invisible dummy button with some unique name or id, and call click() on that.
So if you have a form like this:
Code: Select all
<form name='myform'><input type='text' name='submit'><input type='submit' style='display:none' id='blahh'></form>