Attaching code to a button or image in Foundry3?

Hi. Apologies if this is a newbie question!

I’m using Foundry to build a site that also uses VibraLogix SiteLok to create a members only area.
I’m relatively new to Foundry, so hopefully this is an easy answer.

what I want to do is have a button or an image on my site which, when the user clicks it, it will be able to call a php function from the SiteLok API (e.g. to change the group a user belongs to).

Where should I look in Foundry3 to give the user the ability to click on something and be able to attach a code snippet when the button or image is selected?

Many thanks

Not sure if this is what you are after, it might be so you can change the detail if different. I use attributes on buttons to trigger functions in HTML interactive animation or interactive 3D content. So the buttons aren’t links, but are calling a function instead. To do this set your link to javascript void as seen in the screenshot (you could use two hash symbols instead) this just makes it a null link. Then in the attributes add ID as a title then the ID/Name of the function you are wanting to trigger. As I say, I’m not sure if this is what you are after, it just sounded a little like it was something more than using a button for a link so might be what you after.

1 Like

Actually just thinking on from the last post I put there, although that’s the way I did it, I remembered there was some issue I had when switching to F3 from a different framework, have just gone back to one of my files and had a look and remembered now looking, although that process does attach an id for a function to trigger, F3 created the code a little different to how I used to use it. I therefore used Press by 1LD for the buttons on interactive features that created the code id=“whatever-I-what-to-name-it”. That may be the problem you are having, you put the id in using attributes but don’t get the code you want. I know I played around with a ton of different approaches and couldn’t get it to work. This is mainly for interactive 3D where I want a button to activate a page global page function outside of an iframe using a parent child setup to activate content in the iFrame. Try it with F3 buttons, see if works for you, if not then experiment the same process but with a standard Stacks button and see if you get the response you are after. Possibly.

Attached are two screenshots, one using an F3 button the other using a non-F3 button.


1 Like

Thanks for the suggestion. I’m looking to launch some PHP code when a button is clicked via an API. Normally I’d enter that into an HTML stack.

I was thinking a work around would be to use the button to fire a modal pop up, insert the HTML stack into the modal so it activates with a message to say “done” or something like that.

I guess that’d work. If anyone can suggest another way to launch a php code snippet directly from clicking on an image or button, I’d love to hear your ideas.

Thanks!

1 Like

You could create come PHP code to echo a button, including your PHP code within an HTML tool on your page. Foundry is built with Bootstrap 5 at its core, so you can use some of the code from Bootstrap itself to build your button if you like.