Jump to content

Run PHP if form submit() is ran by onclick on div.


00stuff

Recommended Posts

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,

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.