00stuff Posted August 11, 2011 Share Posted August 11, 2011 Hi guys. I am having a little trouble making a script work. What I am trying to do is run a PHP script after a form is submitted by the click of a div. This is my code: <form name='form_name' method='post' action=''> <input type='text' name='field1'> </form> <div onclick='document.form_name.submit();'>Click Me!</div> <?php if(isset($_POST['submit'])) { echo 'It workded!'; $field_1 = $_POST['field1']; } ?> That is not working though. I think they way I have it written it will need an actual submit button with the name 'submit'. Does anyone know how I can make this work without using an actual button and still using the div as a button? Thanks in advanced, Link to comment https://forums.phpfreaks.com/topic/244533-run-php-if-form-submit-is-ran-by-onclick-on-div/ Share on other sites More sharing options...
Psycho Posted August 11, 2011 Share Posted August 11, 2011 That should submit the form. I think the problem is how you are checking if the form was submitted on the processing page where you use if(isset($_POST['submit'])) { There is no field named 'submit' on your form - at least I don't see one. But, you do have a field named 'field1'. Use that field name to check if the form was posted if(isset($_POST['field1'])) { Although there are better methods of checking form submission. Link to comment https://forums.phpfreaks.com/topic/244533-run-php-if-form-submit-is-ran-by-onclick-on-div/#findComment-1256068 Share on other sites More sharing options...
00stuff Posted August 11, 2011 Author Share Posted August 11, 2011 I'll try that for now. Thanks. Link to comment https://forums.phpfreaks.com/topic/244533-run-php-if-form-submit-is-ran-by-onclick-on-div/#findComment-1256078 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.