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. Link to comment https://forums.phpfreaks.com/topic/74080-solved-automatic-form-submit-not-working/ Share on other sites More sharing options...
env3rt Posted October 20, 2007 Author Share Posted October 20, 2007 bump Link to comment https://forums.phpfreaks.com/topic/74080-solved-automatic-form-submit-not-working/#findComment-374013 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. Link to comment https://forums.phpfreaks.com/topic/74080-solved-automatic-form-submit-not-working/#findComment-374028 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 Link to comment https://forums.phpfreaks.com/topic/74080-solved-automatic-form-submit-not-working/#findComment-374043 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. Link to comment https://forums.phpfreaks.com/topic/74080-solved-automatic-form-submit-not-working/#findComment-374066 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? Link to comment https://forums.phpfreaks.com/topic/74080-solved-automatic-form-submit-not-working/#findComment-374069 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 Link to comment https://forums.phpfreaks.com/topic/74080-solved-automatic-form-submit-not-working/#findComment-374070 Share on other sites More sharing options...
env3rt Posted October 20, 2007 Author Share Posted October 20, 2007 Omg thanks finally Link to comment https://forums.phpfreaks.com/topic/74080-solved-automatic-form-submit-not-working/#findComment-374071 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.