This is a discussion on PHP and HTML within the PHP Programming forums, part of the Web Development category; Hi, PHP and HTML interact a lot: PHP can generate HTML, and HTML can pass information to PHP. we start ...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
|
#1
| |||
| |||
| Hi, PHP and HTML interact a lot: PHP can generate HTML, and HTML can pass information to PHP. we start discussing on this regards
__________________ With, J. Jeyaseelan Everything Possible |
|
#2
| |||
| |||
| Encoding/decoding the value to the html form component Assuming that you have a string $data, which contains the string you want to pass on in a non-encoded way HTML interpretation. In order to specify a random string, you must include it in double quotes, and htmlspecialchars() the whole value. URL: A URL consists of several parts. If you want your data to be interpreted as one item, you must encode it with urlencode(). Here the example for A hidden HTML form element PHP Code:
__________________ With, J. Jeyaseelan Everything Possible Last edited by Jeyaseelansarc : 03-12-2008 at 11:06 PM. |
|
#3
| |||
| |||
| Hi, From the previous example, It is wrong to urlencode() $data, because it's the browsers responsibility to urlencode() the data.
__________________ With, J. Jeyaseelan Everything Possible |
|
#4
| |||
| |||
| Example for data to be edited by the user: PHP Code: Upon submitting, either via GET or POST, the data will be urlencoded by the browser for transferring, and directly urldecoded by PHP. So in the end, you don't need to do any urlencoding/urldecoding yourself, everything is handled automagically.
__________________ With, J. Jeyaseelan Everything Possible |
|
#5
| |||
| |||
| Here example to send in URL: PHP Code: You'll notice that the & in the URL is replaced by &. Although most browsers will recover if you forget this, this isn't always possible. So even if your URL is not dynamic, you need to htmlspecialchars() the URL.
__________________ With, J. Jeyaseelan Everything Possible |
|
#6
| |||
| |||
| Create arrays in a HTML <form>? To get your <form> result sent as an array to your PHP script you name the <input>, <select> or <textarea> elements like this: <input name="MyArray[]" /> <input name="MyArray[]" /> <input name="MyArray[]" /> <input name="MyArray[]" /> Notice the square brackets after the variable name, that's what makes it an array. You can group the elements into different arrays by assigning the same name to different elements: <input name="MyArray[]" /> <input name="MyArray[]" /> <input name="MyOtherArray[]" /> <input name="MyOtherArray[]" /> This produces two arrays, MyArray and MyOtherArray, that gets sent to the PHP script. It's also possible to assign specific keys to your arrays: <input name="AnotherArray[]" /> <input name="AnotherArray[]" /> <input name="AnotherArray[email]" /> <input name="AnotherArray[phone]" /> The AnotherArray array will now contain the keys 0, 1, email and phone. Note: Specifying an arrays key is optional in HTML. If you do not specify the keys, the array gets filled in the order the elements appear in the form.
__________________ With, J. Jeyaseelan Everything Possible |
|
#7
| |||
| |||
| To get all the results from a select multiple HTML tag? The select multiple tag in an HTML construct allows users to select multiple items from a list. These items are then passed to the action handler for the form. The problem is that they are all passed with the same widget name. I.e. <select name="var" multiple="yes"> Each selected option will arrive at the action handler as: var=option1 var=option2 var=option3 Each option will overwrite the contents of the previous $var variable. The solution is to use PHP's "array from form element" feature. The following should be used: <select name="var[]" multiple="yes"> This tells PHP to treat $var as an array and each assignment of a value to var[] adds an item to the array. The first item becomes $var[0], the next $var[1], etc. The count() function can be used to determine how many options were selected, and the sort() function can be used to sort the option array if necessary. Note that if you are using JavaScript the [] on the element name might cause you problems when you try to refer to the element by name. Use it's numerical form element ID instead, or enclose the variable name in single quotes and use that as the index to the elements array, for example: variable = documents.forms[0].elements['var[]'];
__________________ With, J. Jeyaseelan Everything Possible |
|
#8
| |||
| |||
| To pass a variable from Javascript to PHP Since Javascript is (usually) a client-side technology, and PHP is (usually) a server-side technology, and since HTTP is a "stateless" protocol, the two languages cannot directly share variables. It is, however, possible to pass variables between the two. One way of accomplishing this is to generate Javascript code with PHP, and have the browser refresh itself, passing specific variables back to the PHP script. The example below shows precisely how to do this -- it allows PHP code to capture screen height and width, something that is normally only possible on the client side. PHP Code:
__________________ With, J. Jeyaseelan Everything Possible |
|
#9
| |||
| |||
| Hi Buddies Here another one example to embed HTML into PHP PHP Code: Falcon ![]() |
|
#10
| |||
| |||
| Hi Buddies use cookie to passing javascript variable to php variable. see this example. HTML Code: <HTML> <TITLE>Getting screen resolution........ Please wait....................</TITLE> <!-- no personal urls please --> <HEAD> <script language="javascript"> <!-- writeCookie(); function writeCookie() { var today = new Date(); var the_date = new Date("December 31, 2099"); var the_cookie_date = the_date.toGMTString(); var the_cookie = "ur_width=" + screen.width ; var the_cookie = the_cookie + ";expires=" + the_cookie_date; document.cookie=the_cookie var the_cookie = "ur_height=" +screen.height; var the_cookie = the_cookie + ";expires=" + the_cookie_date; document.cookie=the_cookie location = 'b.php'; } //--> </script> </HEAD> <BODY> Detecting your screen resolution .........<br>Please wait..................................... </BODY> </HTML> PHP Code: Falcon ![]() |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| html | pav | HTML, CSS and Javascript Coding Techniques | 0 | 08-01-2008 04:09 AM |
| HTML or CSS | capture | Web Design Help | 2 | 03-15-2007 06:21 PM |
| html | djree | HTML, CSS and Javascript Coding Techniques | 1 | 03-08-2007 08:12 PM |
| swf in html | nssukumar | Flash Actionscript Programming | 2 | 03-06-2007 04:10 AM |
| HTML vs. CSS | Joe | HTML, CSS and Javascript Coding Techniques | 3 | 03-03-2007 07:12 PM |
Our Partners |