471,306 Members | 840 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,306 software developers and data experts.

This class returns HTML content but fails in producing globals, why?

The following class is supposed to produce a series of HTML dropdowns
and HTML text fields based solely upon variable names for month, day
and year passed into it. Those variable names will correspond to
actual variables with values that are passed into the preSelect()
function inside the methods (that function is called from an outside
parent script included). However, upon careful inspection the global
function does not globalize anything within any method.

Can someone look at this and tell me what I did wrong?

Thanx
Phil

// USE THIS CLASS TO GENERATE A SERIES OF DROPDOWNS AND TEXT FIELDS
PERTAINING TO MONTH / DAY / YEAR
class DropdownGenerator {
var $hasMonth, $hasDay, $hasYear,
$monthVar, $dayVar, $yearVar,
$yearFieldLength,
$monthArray;

function DropdownGenerator($monthVar = '', $dayVar = '', $yearVar =
'', $yearFieldLength = 4) {

$this->yearFieldLength = $yearFieldLength;
foreach (array('month', 'day', 'year') as $key => $val) {
$this->{$val . 'Var'} = ${$val . 'Var'};
$this->{'has' . ucfirst($val)} = (strlen($this->{$val . 'Var'}) >
0) ? 1 : 0;
if (strlen($this->{$val . 'Var'}) > 0) global ${$this->{$val .
'Var'}};
}

$this->monthArray = array('01' => 'January',
'02' => 'February',
'03' => 'March',
'04' => 'April',
'05' => 'May',
'06' => 'June',
'07' => 'July',
'08' => 'August',
'09' => 'September',
'10' => 'October',
'11' => 'November',
'12' => 'December'
);

}

function getMonthDropdown() { // STRING "METHOD" TO PRODUCE MONTH
DROPDOWN
global ${$this->monthVar};

if (!$this->hasMonth) return '';
$html = $this->monthVar . ' = ' . ${$this->monthVar} . '<select
size="1" name="' . $this->monthVar . '">';
foreach ($this->monthArray as $key => $val)
$html .= '<option value="' . $key . '"' .
preSelect(${$this->monthVar}, $key) . '>' . $key . ' - ' . $val .
'</option>';
$html .= '</select>';
return $html;
}

function getDayDropdown() { // STRING "METHOD" TO PRODUCE DAY
DROPDOWN
global ${$this->dayVar};

if (!$this->hasDay) return '';
$html = '<select size="1" name="' . $this->dayVar . '">';
for ($i = 1; $i <= 31; $i++) {
$myDay = ($i < 10) ? '0' . $i : $i;
$html .= '<option value="' . $myDay . '"' .
preSelect(${$this->dayVar}, $myDay) . '>' . $myDay . '</option>';
}
$html .= '</select>';
return $html;
}

function getYearText() { // STRING "METHOD" TO PRODUCE YEAR TEXT
FIELD
global ${$this->yearVar};

if (!$this->hasYear) return '';
$html = '<input type="text" name="' . $this->yearVar . '" value="' .
${$this->yearVar} . '" size="' . $this->yearFieldLength . '">';
return $html;
}

}
Jul 17 '05 #1
0 1556

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Dafella | last post: by
6 posts views Thread by Lars Plessmann | last post: by
6 posts views Thread by scottyman | last post: by
2 posts views Thread by Jim Carr | last post: by
71 posts views Thread by Murray R. Van Luyn | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.