Bright
Bright

Reputation: 63

how to check if submit button is clicked using php in the same page

<form method="get" action="<?php echo $_SERVER['PHP_SELF']?>">

<h3>Select your product and click submit</h3><br />

<select name="prod">

<option value="default">Select your product</option>

<option value="os">Operating Systems</option>

<option value="mobile">Smart Mobiles</option>

<option value="mobile">Computers</option>

<option value="shirt">Shirts</option>

</select><br /><br />

<input type="submit" value="Submit" name="submit"/>

</form>

Upvotes: 0

Views: 8432

Answers (3)

Lior
Lior

Reputation: 6051

You could check if the value of the submit control exists.

if(isset($_GET['submit']))

This way, when the form will be posted the $_GET['submit'] will have a value, then you can know that the form was posted.

Upvotes: 3

Michael O&#39;Brien
Michael O&#39;Brien

Reputation: 60

much easier to use .click() from jQuery to check but add a boolean field for submit in db

Upvotes: -1

Quentin
Quentin

Reputation: 944559

The submit button will be a successful control if it has been clicked. Check for the existence of a submit key in the form data.

Upvotes: -1

Related Questions