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,

Link to comment
Share on other sites

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