Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old December 12th, 2009, 08: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>";
?>
Reply With Quote
  #2 (permalink)  
Old December 13th, 2009, 09: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.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 07:10 PM
scope problem jc Javascript 0 July 29th, 2003 09:27 AM



All times are GMT -4. The time now is 01:18 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.