[Resolved][Plug-ins Php] Conditionnal if doesn't work

ThierryM

Member
Hi,
I want to use a plug-in php in form with OnBeforeProcess.
Code:
//permet de r?cup?rer la valeur du groupe "josto_adhesions_gestion"
$usep=$formModel->formData['josto_adhesions_gestion___usep'];

//Harmonise la valeur du champ 'cb_usep' avec celui du groupe "josto_adhesions_gestion"
$formModel->updateFormData('josto_comprofiler___cb_usep',$usep,true);

//echo "<pre>";print_r($usep);exit;
if ($usep === 1)
{
  $formModel->updateFormData('josto_user_usergroup_map___group_id',27,true);
}
else {
  $formModel->updateFormData('josto_user_usergroup_map___group_id',26,true);
}

All it's working, except the instructions into the conditionnal "if" (with or without "else") :
The $usep variable contain the correct value (0 or 1).
and if I erase the condition, the alone line updateFormData works :
Code:
$formModel->updateFormData('josto_user_usergroup_map___group_id',27,true);

So I think I make a mistake but I don't see where... Or is this maybe a bug ?
Thanks for your help, regards
 
You are using ===, which is "strongly typed", meaning that it requires both values to be of the same type, and 1 (an integer) does not === "1" (a string). And the value you get from formData[] will be a string. So either use ==, which loosely typed, so 1 does == "1", or compare with the same type, === "1".

-- hugh
 
Hi Hugh,
Thanks for your help and the explanations.
So I used =="1" (or ==1) but it's only the instruction after "else" that works. It's like the $usep variable was always different from "1" (but when I print it, it's not the case). Or like if the second instruction "updateFormData" always applies. So I don't find my error.
Code:
//permet de r?cup?rer la valeur du groupe "josto_adhesions_gestion"
$usep=$formModel->formData['josto_adhesions_gestion___usep'];
//echo "<pre>";print_r($usep);exit;

//Harmonise la valeur du champ 'cb_usep' avec celui du groupe "josto_adhesions_gestion"
$formModel->updateFormData('josto_comprofiler___cb_usep',$usep,true);

//echo "<pre>";print_r($usep);exit;
if ($usep =="1")
{
  $formModel->updateFormData('josto_user_usergroup_map___group_id',27,true);
}
else {
  $formModel->updateFormData('josto_user_usergroup_map___group_id',26,true);
}

Regards,

Thierry
 
Thanks Troester, you were right.
var_dump ($usep) return :
Code:
array(1) { [0]=> string(1) "1" }

So I modified my condition and now it's working nice :
Code:
//permet de r?cup?rer la valeur du groupe "josto_adhesions_gestion"
$usep=$formModel->formData['josto_adhesions_gestion___usep'];

//Harmonise la valeur du champ 'cb_usep' avec celui du groupe "josto_adhesions_gestion"
$formModel->updateFormData('josto_comprofiler___cb_usep',$usep,true);

//echo "<pre>";print_r($usep);
//var_dump($usep);exit;

if ($usep[0] =="1")
{
  $formModel->updateFormData('josto_user_usergroup_map___group_id',27,true);
}
else
{
  $formModel->updateFormData('josto_user_usergroup_map___group_id',26,true);
}

So the bug was between the keyboard and the seat... as usual :oops:.
Thanks a lot for yours helpful replies.
Regards,

Thierry
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top