Jump to content
Fórum Script Brasil
  • 0

Dúvida na lógica com arrays


Ricardo T. do Prado

Question

Galera,

Problema cruel aqui...

Estou montando um formulário dinâmico, segue código:

foreach ($fields as $value=>$key) {
        
        $tipo[] = $key;
        
        if($key == "dtString") {
             $input[] =  "<input type=text name=$value> $value </br>"; 
        }
        
        if($key == "dtDateTime") {
             $input[] =  "<input type=text name=$value> $value </br>"; 
        }
        
        if($key == "dtDecimal") {
             $input[] =  "<input type=text name=$value> $value </br>"; 
        }
            
        if($key == "dtPass") {
            $input[] =   "<input type=password name=$value> $value </br>";
        } 
            
        if($key =="dtLongText") { 
            $input[] = "<textarea name=$value> </textarea> </br>"; 
        }
        if($key =="dtImage") { 
            
            $input[] = "<input type=file name=$value> $value </br>"; 
        }
        
        if($key == "dtFile") { 
            
            $input[] = "<input type=file name=$value> $value </br>"; 
        }
        
        if($key =="dtHide") { 
            
            $var = explode(',',$value);
            $input[] = "<input type=hidden name=".$var[0]." value=".$var[1]."> </br>"; 
        }
                        
        if($key == "dtLookUp")     {
                            $var = explode(',',$value);
                            conexao();    
                            $wizard = "<select name=".$var[4]."> <option> ---selecione --- </option>";    
                            $sql = mysql_query("select ".$var[1].", ".$var[2]." from ".$var[0]."") or die ("Erro na montagem de um <SELECT> verifique parametros ".mysql_error());
                            while($row = mysql_fetch_row($sql)) {
                                $wizard.="<option value=".$row[0].">  ".$row[1]." </option>";
                            }
                            $wizard.=" </select> ".$var[4]."</br>";
                            $input[] = $wizard;
        }

        
    }
    
    foreach($input as $saida) {
        echo $saida;
    }
Até ai tá beleza, mas o problema é que eu preciso associar esses valores (dtString, dtDecimal, dtFile, etc) quando o formulário for submito. Exemplo; Recupero assim:
$fields = array();
$values = array();                
            
    foreach($_POST as $campos=>$valores){
                            
            $fields[] = $campos;
            $values []  = $valores;    
    }

Só que Preciso associar =>$valores aos (dtString, dtDecimal, etc) que usei ali em cima para criar as input

Por que iria formatar os dados recebido por $_POST de acordo com seu tipo, exemplo

if("dtDecimal) {

str_replace(',',',$valores) // bla bla bla

}

Sacaram? só que não consigo ver lógica/não sei como fazer isso.

Abs.

Edited by Ricardo T. do Prado
Link to comment
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      152.2k
    • Total Posts
      652.1k
×
×
  • Create New...