/    Sign up×
Community /Pin to ProfileBookmark

How can I detect that a button is clicked?

I know if it’s an <input = submit> i can simply use $submit, but what if it’s an <input = button> ?

Thanks for your help.

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJun 21.2006 — I think the only way PHP could know is if the button had an onclick JavaScript event associated with it that did something like changing the value of the button (or perhaps some hidden form element?). But then you're depending upon the client to do some of your work, which is never 100% dependable.

Perhaps if you explain what the purpose is of using an <input type="button"> element in your form, we could suggest an alternative? (For instance, maybe all you need to do is use a <button type="submit"> element, instead.)
Copy linkTweet thisAlerts:
@MonsieurRenardauthorJun 21.2006 — Well the thing is I want to call a javascript to do AJAX stuff when the button is pressed (submit would refresh the page). The script sends a request to another php page which uses registered variables from the current page to do stuff. One of those variables is an array $answers, but it needs to be updated when the button is pressed before the javascript sends a request to the other page, and I think only PHP could update it.

I don't know if I'm making any sense, but I greatly appreciate your help.

PS: The main reason I'm having these problems is because I'm using someone else's PHP code and making it work with AJAX without changing the php too much.
Copy linkTweet thisAlerts:
@chazzyJun 21.2006 — are you using get or post to send the data? where is answers being stored? typically you can't send an "array" over HTTP - because browsers dont really know what that is.
Copy linkTweet thisAlerts:
@MonsieurRenardauthorJun 21.2006 — I'm not sending the array, i'm using session_start, but i still need to update it.
Copy linkTweet thisAlerts:
@felgallJun 21.2006 — All of the fields in the form are sent to the next page in either the $_GET or $_POST variables when the form is submitted with the following exceptions:

Any disabled fields are not sent

Only selected checkboxes and radio buttons are sent

Only the selected button is sent

Only the last field with the same name is sent
×

Success!

Help @MonsieurRenard 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 5.19,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...