Patrioticcow
Patrioticcow

Reputation: 27058

php how to attach a if statement to a button?

I have a I statement;

if($game_set->issue_challenge()){echo "test";}else {"test failed";}

and I have a button:

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

I want to be able to say: if the button isset, then $values = $_POST['gamelist'] and if($game_set->issue_challenge()){echo "test";}else {"test failed";}

I was thinking something like

if (isset($_POST['Submit'])) {
$values = $_POST['gamelist']
if($game_set->issue_challenge()){echo "test";}else {"test failed";}
}

any ideas?

thanks

Upvotes: 1

Views: 3646

Answers (1)

Marc B
Marc B

Reputation: 360752

Assuming you're on a POST form:

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    if (isset($_POST['submit']) && ($_POST['submit'] == 'Submit')) {
       ... it was clicked
    }
}

Upvotes: 1

Related Questions