Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: Array help

  1. #1
    New Coder
    Join Date
    Apr 2007
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Array help

    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 Code:
    <?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?
    Last edited by Iauwak; 08-28-2007 at 06:24 PM.

  • #2
    New Coder
    Join Date
    Apr 2007
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I solved this with a modified:
    http://www.dreamincode.net/forums/showtopic14720.htm

    Which is even better =D


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •