Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5
This is the forum to discuss the Wrox book Beginning PHP4 by Wankyu Choi, Allan Kent, Chris Lea, Ganesh Prasad, Chris Ullman; ISBN: 9780764543647
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 12th, 2009, 09:03 AM
Registered User
 
Join Date: Dec 2009
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Scope of the name attribute

I was wondering what is the scope of the name attribute of a form...actually, in the try it out example for cookies, they have used the name attribute of the <select> control right at the beginning of the document...the code is below:

<?php
//cookies.php
//I AM REFERRING TO THE USAGE HERE
if (!empty($_POST['type_sel'])) {
$type = $_POST['type_sel'];

setcookie("Type", $type, time()+3600);
}

if (!empty($_POST['size_sel'])) {
$size = $_POST['size_sel'];
setcookie("Size", $size, time()+3600);
}

//We define some options for font size and typeface, and as it's now safe to add an //HTML header, we do so:
$type = array("arial", "helvetica", "sans-serif", "courier");
$size = array("1","2","3","4","5","6","7");
echo "<html><head><title>Cookie Test</title></head><body><div align='center'>";

//The following form contains a pair of listboxes, which can be used to specify the //user's preferences:
echo "<form method='POST'>";
echo "What font type would you like to use? ";
echo "<select name='type_sel'>";
echo "<option selected value=''>default</option>";
foreach ($type as $var) {
echo "<option>$var</option>";
}
echo "</select><br><br>";
echo "What font size would you like to use? ";
echo "<select name='size_sel'>";
echo "<option selected value=''>default</option>";

foreach ($size as $var) {
echo "<option>$var</option>";
}
echo "</select><br><br>";
echo "<input type='submit'>";
echo "</form>";

//Finally, we echo out some useful information, and format it using appropriate //settings:
echo "<b>Your cookies say:</b><br>";
echo "<font ";
if (isset($_COOKIE['Type'])) {
echo "face='$_COOKIE[Type]' ";
}

if (isset($_COOKIE['Size'])) {
echo "size='$_COOKIE[Size]' ";
}
echo ">";
if (isset($_COOKIE['Type']))
echo "Type = $_COOKIE[Type]";
echo"<br>";
if (isset($_COOKIE['Size']))
echo "Size = $_COOKIE[Size]";
echo "</font><br>";

echo "<b>Your form variables say:</b><br>";
echo "<font ";

if (isset($_POST['type_sel'])) {
echo "face='$_POST[type_sel]' ";
}

if (isset($_POST['size_sel'])) {
echo "size='$_POST[size_sel]' ";
}
echo ">";
if (isset($_POST['type_sel']))
echo "Type = $_POST[type_sel]<br>";
if (isset($_POST['size_sel']))
echo "Size = $_POST[size_sel]<br>";
echo "</font>";
echo "</div></body></html>";
?>
 
Old December 13th, 2009, 10:55 PM
Authorized User
 
Join Date: Dec 2008
Location: London
Posts: 50
Thanks: 1
Thanked 5 Times in 5 Posts
Default

easy way to learn is play around with the script.

add following line after line which says //cookies.php

PHP Code:
print_r($_POST); 
also try to understand the HTML of the generated page.

kind regards.




Similar Threads
Thread Thread Starter Forum Replies Last Post
"Out of scope" var??? yankleber XSLT 2 March 31st, 2007 03:53 AM
Access to attribute values from class of attribute jacob C# 1 October 28th, 2005 01:11 PM
Scope of array jakeone Beginning PHP 1 November 4th, 2003 08:10 PM
scope problem jc Javascript 0 July 29th, 2003 09:27 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.