On 14 Feb 2002, at 11:09, James Taylor wrote:

> Can someone recommend a better method for doing something like the
> following? All of my programs are written like this, but it's really
> poor form considering I'm not predeclaring my variables, etc.   Only
> thing I can really think of is to assign a value in the form a number
> like 1 or something, then do a if $value == 1 {do something} but that
> seems kinda hokey. Here's an example of something I'd do:

>    if ($submitdata) {
>       dosomething;
>       exit;
>     }
> 
>    echo "<form name=\"form\" action=\"$PHP_SELF?\">\n";
>    echo "  <input type=\"text\" name=\"data\">\n";
>    echo "  <input type=\"submit\" name=\"submitdata\" value=\" Submit
>    \">\n"; echo "</form>\n</body>\n</html>";

Yeah, seems hokey doesn't it :) ... I think about the same thing in 
the code I use with PHP but I think it's the nature of the beast. But 
a "Best Practices" sounds like a great idea that has passed me by 
or I forgot if I've seen it. 

I've been doing PHP for about a month now and here's how what I'm 
doing:

<?php

        
        include_once ( "./CONFIG.inc"); // Config file
        global $Config;

        $question_search_snippet = $Config["Snippets"]->Get("question_search_snippet");
        $AskUs = $Config["Snippets"]->Get("AskUs");
        $Slow_question_search_snippet = 
$Config["Snippets"]->Get("Slow_question_search_snippet");
        
$body = <<<HTML
        Data Here 
        
        </p>
HTML;
        
        
        $Config["PageBuilder"]->Build($PHP_SELF,$body);


?>

Most pages are either like "modules/cgi-script" or a just a page like 
this one.

I really hate globals so I cheat and make an array global :).


My CONFIG.inc makes connections to all "classes" , sets paths 
etc.

Here is how I handle my input date (not my confusion with & for 
references):

$input                                  = &ProcessFormData($GLOBALS);

    function &ProcessFormData(&$GLOBAL_INPUT) {
        $FormVariables = array();
        $input = $GLOBAL_INPUT[HTTP_GET_VARS] ? 
$GLOBAL_INPUT[HTTP_GET_VARS] : 
$GLOBAL_INPUT[HTTP_POST_VARS];
        foreach($input as $Key=>$Value) {
            if(is_array($Value)) {
                foreach($Value as $SubKey=>$SubValue) {
                    $FormVariables[$Key.$SubKey] = $SubValue;
                }
           }else {
               $FormVariables[$Key] = $Value;
           }
        } # End of foreach($input as $Key=>$Value)
        return $FormVariables;

    } # End of function DisplayArrayVariables


Peter
http://www.readbrazil.com/
Answering Your Questions About Brazil

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to