Jump to content

Adding a button with PHP, which could be used for interacting with client side


Recommended Posts

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?

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.

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.

 

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
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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