/    Sign up×
Community /Pin to ProfileBookmark

Where Is The Said Array ?

Folks,

Look at this tutorial.
https://www.geeksforgeeks.org/how-to-call-php-function-on-the-click-of-a-button/

Function: array_key_exists()

[code]
<!DOCTYPE html>
<html>

<head>
<title>
How to call PHP function
on the click of a Button ?
</title>
</head>

<body style=”text-align:center;”>

<h1 style=”color:green;”>
GeeksforGeeks
</h1>

<h4>
How to call PHP function
on the click of a Button ?
</h4>

<?php
if(array_key_exists(‘button1’, $_POST)) {
button1();
}
else if(array_key_exists(‘button2’, $_POST)) {
button2();
}
function button1() {
echo “This is Button1 that is selected”;
}
function button2() {
echo “This is Button2 that is selected”;
}
?>

<form method=”post”>
<input type=”submit” name=”button1″
class=”button” value=”Button1″ />

<input type=”submit” name=”button2″
class=”button” value=”Button2″ />
</form>
</head>

</html>
[/code]

In the code, where is the array that lists the buttons ?
I don’t see any array like these:
$buttons = array(‘button_1′,’button_2’);
$buttons = array(‘0’=>’button_1′,’1′->’button_2’);

Or is php checking inside the built-in fuction ? Which built-in function ? Super Global $_POST ?
$GLOBALS[$_
POST]; //This forum has removed the “_” prior the ‘POST’.
Did I write the Super Global correctly ?

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@NogDogApr 11.2021 — It's just basic form processing in PHP. Since the HTML form at the end is using method="post", when you submit it, the page gets loaded again, and the values in the input form elements get stored in the $_POST array, just like any other post form submission.

(Personally, I prefer to just use isset($_POST['button1']) as opposed to array_key_exists('button1', $_POST), but maybe that's just me.)
Copy linkTweet thisAlerts:
@developer_webauthorApr 14.2021 — @NogDog#1630223

I didn't know that when method='POST', php creates an array called $_POST[]. That is news indeed.

I thought php just remembers the "name=" stuffs into ram somehow.

So, if method='GET', then php auto creates the $_
GET[] array in ram too ?

EDIT: Why is this form making my above 2 lines in 'italic' style ?
Copy linkTweet thisAlerts:
@NogDogApr 14.2021 — > @developer_web#1630316 Why is this form making my above 2 lines in 'italic' style ?

The forum uses a mish-mash of [markdown](https://www.markdownguide.org/getting-started/) and bbcode tags. In markdown, underscores are used to indicate Italics. If you want to have literal underscores such as with variable names, it's best to wrap the text in single back-ticks, like:
<i>
</i>Why is <span><code>$_POST</code></span> populated?

Typing that here without the code tags: Why is $_POST populated?
Copy linkTweet thisAlerts:
@inktApr 15.2021 — @developer_web#1630316
Why is this form making my above 2 lines in 'italic' style ?
You probably have some css that controls the look of your &lt;h4&gt;
Copy linkTweet thisAlerts:
@developer_webauthorApr 18.2021 — @inkt

Ok. Thanks.

But how-about answering my previous post ?
×

Success!

Help @developer_web spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...