Search code examples
phphtmlcsswebmamp

How to put function to this block of PHP code?


i'm just beginner and i want to call function which will be create the "sub buttons" when button is clicked, how i can do it from this block in echo? help pls

<?php function btncreate($filename) {
    echo "<button class='m-1 btn btn-outline-success'>$filename</button>";
}
?>

P.S. i need to do it at the same page with the general buttons

i was trynna to do it by using onclick, putting the JS code inside the echo


Solution

  • First thing first, why do you need to create UI using backend language like that's mostly a Front end language job, Secondly even if you want to do it like this then I say you should use AJAX but that still requires you the combination of Front END with Backend, and if you are looking for a simple button creation upon an event and then save/retrieve something for that button in the backend then I think we can start with JavaScript to create the button on an event (i.e. CLICK) and upon its creation just run an ajax request to save/retrieve whatever you want from that.