...

View Full Version : Array help



Iauwak
08-28-2007, 06:22 PM
Hello,

I want to validate a text area in my template system.

To define a value, I just have to insert:
$template->append("NAME", "VALUE");

I am trying to easily provide text-area status after form submission.

So say it is a select for male or female.

I would define the dependency which would tell the system whether or not to return a value, so that's $error[gender]. Then current is what the value submitted is equal to, so male for example. $options is a comma separated list of possible options (male, female). Status is another variable I use, and isn't important.

Here is the command:
select_status($error[gender], $gender, "male, female", "gender_status")

Here are the codes:


<?php
function select_status($dependancy, $current, $options, $status) {
if (empty($dependancy)) {
$data = explode(",", $options);
foreach ($data as $var) {
if ($var == $current) {
$xf[] = '$template->replace("'.$status.'_'.$var.'", "selected");';
}
else {
$xf[] = '$template->replace("'.$status.'_'.$var.'", "");';
}
}
return $xf;
}
}

?>

My question really is how do I get this to work? I basically want to be able to validate a variable against an array of options. If an option is true then it should return selected, if it's false it should return nothing. I need it to output in $template->append("NAME", "VALUE"); the name should be $status.$var, each variable in the array needs an output in that format.

I was making it an array so that I can do a foreach eval();

Is this possible?

Iauwak
08-28-2007, 09:49 PM
I solved this with a modified:
http://www.dreamincode.net/forums/showtopic14720.htm

Which is even better =D



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum