env3rt Posted October 20, 2007 Share Posted October 20, 2007 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. Quote Link to comment Share on other sites More sharing options...
env3rt Posted October 20, 2007 Author Share Posted October 20, 2007 bump Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted October 20, 2007 Share Posted October 20, 2007 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. Quote Link to comment Share on other sites More sharing options...
env3rt Posted October 20, 2007 Author Share Posted October 20, 2007 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 Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted October 20, 2007 Share Posted October 20, 2007 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. Quote Link to comment Share on other sites More sharing options...
env3rt Posted October 20, 2007 Author Share Posted October 20, 2007 Oh, so how could I get it to work without using the submit button? Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted October 20, 2007 Share Posted October 20, 2007 Its the PHP code thats the problem, you'll want to change your if statement: if ($_POST['subform']){ to something else. Prehaps: if ($_POST['this']){ $_POST['this'] will refer to your textarea, as you named it this Quote Link to comment Share on other sites More sharing options...
env3rt Posted October 20, 2007 Author Share Posted October 20, 2007 Omg thanks finally Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.