Jump to content

[SOLVED] Automatic form submit not working.


env3rt

Recommended Posts

The problem is that when I have javascript automatically submit the form, the php doesn't work, but when I press the submit button it works perfectly. Does anyone know what I am doing wrong?

Code is below.

 


<?php

echo "
<head>
<script>
function yes(){
document.sform.submit()
}
</script>
</head>

<body onKeypress='yes()'>
<form method='post' action='?' name='sform' id='sform'>
<input type='text' id='this' name='this'>
<input type='submit' id='subform' name='subform' value='subform'>
</form>
</body>
";

if ($_POST['subform']){
$page = "expage.html";
$fh = fopen($page, 'w');
$example = $_POST['this'];
fwrite($fh, $example);
fclose($fh);
echo "<script>alert('form submitted')</script>";
}
?>

 

Please help if you can.

Link to comment
Share on other sites

Your id of your submit button need's to be the same as what you are trying to grab through javascript.

It seems to me you are trying to make something simply and generally easy to do into over convoluted code, and

a very roundabout way.

Simply have them submit the form, then do the file saving stuff right after that.

Link to comment
Share on other sites

I could make them click the button but I want it to submit even if they don't click it, and the submit fuction with javascript doesnt work

Well it does work but not in the way you are expecting it to work. Because you are submitting the form when a user enters something into the textbox, and not when the user click the submit button. The submit button is not be sent in the http request ($_POST['subform']).

 

Submit buttons will only be sent in the http request when they are clicked on.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.