kerimatasoy Posted December 27, 2011 Share Posted December 27, 2011 Is it possible adding a button with PHP, which could be used for adding an optional text input field by client side user? My purpose is actually very simple: The client side users could be free creating and adding more and customized variables, which are intended to be used as strings and related or associated variables. So, am I able to do these kind of tasks simply using PHP alone? Or, should I use some JavaScript like technologies to make those functions available in real world's practices? Quote Link to comment https://forums.phpfreaks.com/topic/253871-adding-a-button-with-php-which-could-be-used-for-interacting-with-client-side/ Share on other sites More sharing options...
scootstah Posted December 27, 2011 Share Posted December 27, 2011 PHP is a server side language. You cannot "add a button" with it. You need HTML, and Javascript/AJAX. Quote Link to comment https://forums.phpfreaks.com/topic/253871-adding-a-button-with-php-which-could-be-used-for-interacting-with-client-side/#findComment-1301498 Share on other sites More sharing options...
ManiacDan Posted December 27, 2011 Share Posted December 27, 2011 An entire PHP script executes and dies before anything is seen by the user (for the most part). JavaScript is the (entirely separate) language used to perform actions on the client. Quote Link to comment https://forums.phpfreaks.com/topic/253871-adding-a-button-with-php-which-could-be-used-for-interacting-with-client-side/#findComment-1301506 Share on other sites More sharing options...
AGuyWithAthing Posted December 27, 2011 Share Posted December 27, 2011 PHP + AJAX = Solution. Quote Link to comment https://forums.phpfreaks.com/topic/253871-adding-a-button-with-php-which-could-be-used-for-interacting-with-client-side/#findComment-1301510 Share on other sites More sharing options...
ManiacDan Posted December 27, 2011 Share Posted December 27, 2011 You definitely don't need ajax for this, that's a whole unnecessary level of complexity that you're not ready for. Quote Link to comment https://forums.phpfreaks.com/topic/253871-adding-a-button-with-php-which-could-be-used-for-interacting-with-client-side/#findComment-1301519 Share on other sites More sharing options...
kicken Posted December 27, 2011 Share Posted December 27, 2011 Is it possible adding a button with PHP, which could be used for adding an optional text input field by client side user? Is it possible? Yes. It would be far easier and much more user-friendly to use javascript for this task though. To you PHP you would have to submit your form, and then re-create the entire form, just with an extra field, while also maintaining anything they had already typed in so they don't have to type it in again. With javascript, you can just use a couple DOM methods to create a new field and add it to the page, quick and simple. Then just make sure your PHP script is aware of these additional fields and processes them. Usually when I do something like these the dynamic fields are named as an array and I just use a foreach() loop on the php end. Quote Link to comment https://forums.phpfreaks.com/topic/253871-adding-a-button-with-php-which-could-be-used-for-interacting-with-client-side/#findComment-1301544 Share on other sites More sharing options...
kerimatasoy Posted December 27, 2011 Author Share Posted December 27, 2011 Thank you all, I've got some more clues now... Quote Link to comment https://forums.phpfreaks.com/topic/253871-adding-a-button-with-php-which-could-be-used-for-interacting-with-client-side/#findComment-1301565 Share on other sites More sharing options...
ManiacDan Posted December 27, 2011 Share Posted December 27, 2011 From the new user guide I wrote for devshed: The follow items are separate languages and technologies that have nothing to do with each other at the fundamental level: PHP MySQL Regular Expressions HTML/CSS JavaScript/AJAX/Jquery Those items above, when combined properly by a person skilled in all 5 of them, create a fully functioning website. They are NOT the same language, and an expert in one of them is not necessarily an expert in another. Most of the moderators of the PHP boards are experts in all 5 simply through virtue of experience (and being awesome). What most new developers fail to understand is that PHP doesn't "know" anything about your HTML form or your MySQL database. PHP "knows" only PHP things. You must tell it, specifically and explicitly, if you want it to fetch information from a database, or receive information from an HTML form. Speaking of which, PHP scripts ONLY execute from the moment you click a link until the moment the page is done being displayed. That's all. Scripts can't "wait" for user input, they don't "remember" anything that happened before. Each PHP document is an entirely separate program that has no relation to the OTHER PHP documents on your system. In order to give the impression that your various PHP pages are a cohesive system, you need to make use of cache (APC cache or memcache), databaes, the session, and various other techniques to maintain user flow. You will also have to make sure your HTML output reflects the same styles so the look and feel is maintained. You can do this LATER. Get the PHP working first. -Dan Quote Link to comment https://forums.phpfreaks.com/topic/253871-adding-a-button-with-php-which-could-be-used-for-interacting-with-client-side/#findComment-1301578 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.