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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.