By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,047 Members | 1,253 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,047 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.