Fill in only one field

Asked

Viewed 35 times

0

I have 6 filters in a form... Only one filter can be filled. I’ve tried using a XOR, using a flag, but not the right one:

// rgn20180711 TrixDes : inclusão de campos que permitem buscar o codigo pelo nome
if ($fp["Param.CodPadEdicao"]!="" xor $fp["Param.CodDominio"]!="" xor $fp["Param.Tabela"]!="" 
xor $fp["Param.CodFuncional"]!="" xor $fp["Param.CodCampo"]!="" xor (($fp["Param.NumLanIni"] =! "") && ($fp["Param.Tipo"] =! "")))
    MessImg("Apenas uma das informações devem ser preenchidas. Caso seja o código, o tipo é necessário!", MESSERRO, true);

if ($fp["Param.CodPadEdicao"]!="") //Padrão de Edição
{   
    $fp["Param.NumLanIni"] = $fp["Param.CodPadEdicao"]; 
    $fp["Param.Tipo"] = "P";
}
if ($fp["Param.Tabela"]!="")//tabela
{   
    $fp["Param.NumLanIni"] = $fp["Param.Tabela"];
    $fp["Param.Tipo"] = "A";
}
if ($fp["Param.CodCampo"]!="")//Campo de Tabela
{   
    $fp["Param.NumLanIni"] = $fp["Param.CodCampo"]; 
    $fp["Param.Tipo"] = "T";
}
if ($fp["Param.CodDominio"]!="") //Domínio
{   
    $fp["Param.NumLanIni"] = $fp["Param.CodDominio"]; 
    $fp["Param.Tipo"] = "D";
}
if ($fp["Param.CodFuncional"]!="")//Funcionalidade
{   
    $fp["Param.NumLanIni"] = $fp["Param.CodFuncional"]; 
    $fp["Param.Tipo"] = "F";
}

it only sure if I don’t use these two fields that necessarily need to be filled together:

(($fp["Param.NumLanIni"] =! "") && ($fp["Param.Tipo"] =! ""))

in case I would have to test if more than one field is filled return an error saying that only one field may be filled. What I’m doing wrong?

  • It would not be the case to use elseif?

  • a elseif in each test? if I fill more than one field the vector will come back filled can enter an unwanted elseif! in case the first one comes in the vector!

  • the correct one would be elseif, which would meet his need because if he found any of them would stop and fill.

  • I totally comped @Otto.. however the error is not being treated... it will take what comes first in the vector and will not prevent the user from filling more than one field!

  • Ever thought of doing this with javascript ? filled in a clear field the rest heheheh

  • It would be easier for sure... but I’m not allowed to move JS code =/ The same filters are used in various system features!

  • Why don’t you solve this with Javascript and jQuery? Use a logic where, when a filter is filled/selected, other inputs are disabled.

  • Guys... as I can not touch the JS, I approached differently... I made queries with all fields filled and returned all of them! Thank you for the force!

Show 3 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.