PHP Field Forwarder

This function is great for when you have a multi-page form such as an application. This function forwards fields on one page to hidden fields on the next page, and so on. Very simple to call. The beauty of it is, it also will handle arrays with multiple dimensions. If you have a field with the same name on the next form, it's a good rule to call field_forwarder() at the BEGINNING of your form so that when that form is passed, the field (with the same name) will overwrite the previous form. It's also good to put field_forwarder() at the top so the final page will have all the fields in the order of the application. This is a recursive function, i.e. it re-calls itself when it encounters form elements that are arrays such as: Finally, if you wish to print out PHP code of the array instead of hidden fields, add this line right before you call field_forwarder(): $FFoutputType = 'print'; and it will print out, in text form, the values of the fields as php variables – this is great for storing php code in a database.

Code 1

Usage Example

code goes here

Server Side Code

function field_forwarder(){
    global $_POST, $rEM979, $FFoutputType;
    //get the arguments passed
    $argList = func_get_args();
    //globalize any other set of instructions
        eval('global $' . $argList[count($argList)-1] . ';');
    //set the default set of values to convert
            //if the function is initially passed without parameter we're looking in $_POST
            $argList[0] = '_POST';
            $startValue = $_POST; 
            if(sizeof($startValue)==0){return false;}
            eval( '$rEM979["' . $argList[0] . '"] = $' . $argList[0] . ';');
            $argList[0] = 'rEM979';
            $startValue = $rEM979;
            eval( '$startValue = $' . $argList[1] . '["' . $argList[0] . '"];');
                $intersperse .= '["' . $argList[$e] . '"]';
            eval( '$startValue = $' . $argList[count($argList)-1]  . $intersperse . ';');
        foreach($startValue as $n => $v){
                //call the function again
                $shiftArguments = '';
                    $shiftArguments .= '"' . $argList[$w] . '", ';
                $shiftArguments = substr($shiftArguments, 0, strlen($shiftArguments)-2);
                eval('$fieldForwarder .= field_forwarder("' . $n . '"' . substr(',',0,strlen($shiftArguments)) 
                                      . ' ' . $shiftArguments . ');');
                //we have an root value finally
                    //actual output
                    if($FFoutputType == 'print'){
                        $fieldForwarder .= "$$n = '$v';n";
                        $fieldForwarder .= "<input type="hidden" name="$n" value="" . htmlentities(stripslashes($v)) . "">n";
                    $indexString = '';
                        $indexString .= '[' . ((!is_numeric($argList[$g]) and $FFoutputType=='print')?"'":'') . 
                        $argList[$g] . ((!is_numeric($argList[$g]) and $FFoutputType=='print')?"'":'') . ']';
                    $indexString .= '[' . ((!is_numeric($n) and $FFoutputType=='print')?"'":'') . 
                    $n . ((!is_numeric($n) and $FFoutputType=='print')?"'":'') . ']';
                    //actual output
                    if($FFoutputType == 'print'){
                        $fieldForwarder .= "${$argList[count($argList)-2]}$indexString = '$v';n";
                        $fieldForwarder .= "<input type="hidden" name="{$argList[count($argList)-2]}$indexString" value="" 
                                        . htmlentities(stripslashes($v)) . "">n";
return $fieldForwarder;
}//end field_forwarder()

Client Side Code

Client side code is inherently insecure and error prone. It should be used to reduce load on server, and input verified by server. Please include server verification code also in this section.

Description, change title as needed

code goes here

Candidate Code Suggestions

Add your suggestions and links here.