tom.park89 Posted December 31, 2011 Share Posted December 31, 2011 Hi Guys, I am writing a web site for a Company. I have two issues the First one is how can or is it possable to check weather a user is logged in and then call on of two functions depending on the outcome. The second one and the more important ones is it possable to call a PHP Function by a user Clicking a Link or a button? If it is possable how would I go about doing this. Each functions build a different section of the site so for Example; The Function 'Data' will bring back a table displaying the Data from a set table, and then the Function 'Data_Input' would display a different page that allows the users to input data to the tables. I don't want these two functions to be dispalying at the sametime but to one Display and then the other and so on for other functions. Quote Link to comment https://forums.phpfreaks.com/topic/254129-calling-php-funcitons-using-buttons/ Share on other sites More sharing options...
KevinM1 Posted December 31, 2011 Share Posted December 31, 2011 Yes to both. What have you tried? Quote Link to comment https://forums.phpfreaks.com/topic/254129-calling-php-funcitons-using-buttons/#findComment-1302851 Share on other sites More sharing options...
tom.park89 Posted January 3, 2012 Author Share Posted January 3, 2012 I have answered my first Question, the answer to that one was right in front of me. As for the Second question (Call PHP Functions from Button Click) I'm not sure how to even start going about doing this. I was thinking may I would have to use Java Script to do this or could it be done just using HTML and PHP. I was thinking something like <input type='button' name='home' onclick='functionanem' > Or something similar, I having a mental block on php as I haven't used it in about 6 months as I have been working on a .NET project. Any pointers or sujestion as to how I could go about doing this would help me alot. Thanks for any posts or tips. Regards Thomas Quote Link to comment https://forums.phpfreaks.com/topic/254129-calling-php-funcitons-using-buttons/#findComment-1303808 Share on other sites More sharing options...
scootstah Posted January 3, 2012 Share Posted January 3, 2012 You can't use onclick events with PHP. But you can use AJAX like that. Quote Link to comment https://forums.phpfreaks.com/topic/254129-calling-php-funcitons-using-buttons/#findComment-1303809 Share on other sites More sharing options...
KevinM1 Posted January 3, 2012 Share Posted January 3, 2012 Ajax isn't necessary unless you don't want the page to refresh. The bare-bones basic version would be to simply make the buttons form submit buttons, and have your page post to itself. Based on what button was pressed, different info would be shown. That's how ASP.NET webforms tend to work (have you ever noticed how everything is actually taking place in a form, hense the term 'webforms'?). This is a common pattern on the web. For more info google 'page controller'. Quote Link to comment https://forums.phpfreaks.com/topic/254129-calling-php-funcitons-using-buttons/#findComment-1303927 Share on other sites More sharing options...
tom.park89 Posted January 5, 2012 Author Share Posted January 5, 2012 Ok, the ajax idea sound good. It would be realy nice if I could do it without reading the page, but I post some vars that are used to retreave data such as user ID or Uername. Is there any good Tutorials on ajax page control? Quote Link to comment https://forums.phpfreaks.com/topic/254129-calling-php-funcitons-using-buttons/#findComment-1304575 Share on other sites More sharing options...
Labradoodle-360 Posted January 6, 2012 Share Posted January 6, 2012 Not to be rude, at all, but if you don't know PHP too extremely well, I doubt you'll want to venture down the road of AJAX as you'll need to know PHP, and JavaScript (fairly well). Might I suggest looking into the possibility of just using jQuery? If you don't need to fetch anything dynamic, jQuery should work just fine. Quote Link to comment https://forums.phpfreaks.com/topic/254129-calling-php-funcitons-using-buttons/#findComment-1304703 Share on other sites More sharing options...
tom.park89 Posted January 6, 2012 Author Share Posted January 6, 2012 It's not I don't know PHP that well, I have used it on projects before. I just I haven't used in over a year and I'm just trying to refresh my memory on what I can and carn't do with it. I have spent the last year teaching myself C# and .NET Programming as my employer wanted us all to work on a .net project, but now they have put some of use back on PHP projects as we mainly run Apache Servers. AJAX is something I haven't realy looked at in the past as I haven't needed anything other than what you can do in PHP. But I will be taking a good look at it now. Quote Link to comment https://forums.phpfreaks.com/topic/254129-calling-php-funcitons-using-buttons/#findComment-1304995 Share on other sites More sharing options...
moondran Posted January 6, 2012 Share Posted January 6, 2012 Try using xajax it’s a simple and fast to understand, http://xajaxproject.org/ Quote Link to comment https://forums.phpfreaks.com/topic/254129-calling-php-funcitons-using-buttons/#findComment-1305000 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.