<?php   ### get_btn.php ###


#------------------------------------------------------------------------------

    function linearize($_source, &$_target, $path='', $sep='_')
    {
        if (is_array($_source))
        {
            foreach($_source  as $key => $val)
            {
                linearize($val, &$_target, $path.$sep.$key, $sep);
            }    
        }
        else
        {
            $_target[] = ltrim($path, $sep);
        }
    }

#------------------------------------------------------------------------------

    function make_deep_array($array_pathstr, $value=NULL, $sep='.')
    {
        $_arr = array();
        $array_pathstr = trim($array_pathstr, $sep);
        $_ref =& $_arr;

        while (strlen($array_pathstr) > 0)
        {
            $path = strtok($array_pathstr, $sep); 
            $array_pathstr = substr($array_pathstr,strlen($path)+1);
            $_ref[$path] = NULL;
            $_ref =& $_ref[$path];
        }
     
        $_ref = $value;
     
        return $_arr;
    }

#-----------------------------------------------------------------------------------    

    function get_btn()
    {
        $btn = false;
        $key = false;

        if (isset($_POST['btn']) and count($_POST['btn'])==1 )
        {
            #Kopie erstellen
            $btn = $_POST['btn'];   
        }

        while(is_array($btn))
        {
            if (count($btn) != 1) return false;  ## fake!    ####### LOG-FUNKTION einbauen ######
            ## hier darf nur mit Kopie gearbeitet werden, weil das Array
            list($key, $btn) = each($btn);  ## aufgefressen wird
        }

        return $key;
    }

#===================================================================================
# php main
#===================================================================================


$_btn_path = array();
if (isset($_POST['btn'])) { linearize($_POST['btn'], $_btn_path  ); }
$btn = get_btn();

####################################################################################
# HTML Output
####################################################################################
?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <title>get_btn</title>

  <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
  <meta name="robots" content="index,follow">
</head>

<body>

<pre>
<?php #reset($_POST); 
      echo htmlspecialchars(print_r($_POST,1)); ?>
</pre>

<p><?php echo "<b>Button:</b> $btn"; ?></p> 
<p><?php echo "<b>Button-Kontext:</b> ".(isset($_btn_path[0])?$_btn_path[0]:'nicht definiert'); ?></p> 

<form action="<?php echo $_SERVER['SCRIPT_NAME']; ?>" method="post" enctype="multipart/form-data">
  
    <input type="text" name="data[vorname][1][a]" size="40" value=""><br>
    <input type="text" name="data[nachname]" size="40" value=""><br>
    <input type="text" name="data[strasse]" size="40" value=""><br>
    <input type="text" name="data[plz]" size="6" value="">
    <input type="text" name="data[ort]" size="33" value=""><br>

<!--    <input type="hidden" name="btn[form][17778][nav][fake]" value="geschummelt"> -->
    
    <input type="submit" name="btn[form][17663][nav][prev]" value="&lt; zurück">  
    <input type="submit" name="btn[form][17554][showscript]" value="Script anzeigen">
    <input type="submit" name="btn[form][17663][nav][next]" value="weiter &gt;">
  
</form>    

</body>
</html>
