Jump to content

How to set <button> action?


MattL019

Recommended Posts

Hey. So I'm using the <button> tags to create buttons such as "Follow", "Message", etc. I am wondering if there is any way I can set an action for it, similar to the <form> tag? If not, how else would I go about linking it to a php script?

 

Also, is <button> clicks client-side? If so I can't imagine it would ever work with PHP.

 

Here is my solution:

Have the buttons use javascript to set the GET variable. Then, in PHP check the GET variable for certain values. e.g

domain.com/index.php?follow=yes&user='uid'

 

This way in the future people could make 'quick links' to follow a certain user, etc. I'm just looking for insight into the best way. 

Link to comment
Share on other sites

I am wondering if there is any way I can set an action for it, similar to the

tag?
Actually yes, but there would have to be a
somewhere on the page for it to use.

 

If not, how else would I go about linking it to a php script?

How about AJAX?

 

Also, is

Everything that happens on the client happens on the client. PHP can only get involved if there's a connection made to it, like with a form or AJAX or WebSockets.

 

Here is my solution:

Have the buttons use javascript to set the GET variable. Then, in PHP check the GET variable for certain values. e.g

domain.com/index.php?follow=yes&user='uid'

That would require page navigation, so you might as well just use a regular form.

 

This way in the future people could make 'quick links' to follow a certain user, etc. I'm just looking for insight into the best way.

Any reason why you aren't just using a link?

 

But note that if using a URL is enough to cause someone to follow someone then that can and will be abused. There should be a submitted form (with POST) including a random, unique identifier so you know that the following is intentional. The identifier is actually quite important.

 

Of course there's nothing stopping you from using a link to show a page to prompt the user whether they want to follow. On your own site you can use AJAX (as long as it also uses the identifier) so that the user doesn't have to browse to a new page. Mixing Javascript into links like that is a common practice.

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.