Forums

Adding php to form

chriso0258 20 Mar, 2015
Hello,

In my form I have the following custom code:


<tbody>
<tr>
<td>Status: </td>
<td>{equipinfo.class}</td>
</tr>
</tbody>


Currently the class code (equipinfo.class) is displayed like this - SN, PN, SA, etc.
What I would like to do is add some php code to print out a better description. Such as, if equipinfo.class == "SN" echo "State Network". If equipinfo.class == PN echo "Private Network", etc.
I've tried various methods but I'm not sure how to format the if statement. For example, I've tried,


<td>
<?php
if (equipinfo.class == "SN")
{
     echo "State Network";
}
?>
</td


I've also tried putting the curly brackets around the equipinfo.class but still no avail. How should I format my code?

Thanks so much for your help.

Chris
chriso0258 23 Mar, 2015
Hello Bob and thanks for your reply. I looked very carefully through the FAQ and don't see an answer. Here is what the debugger shows:


Array
(
    [cid] => 489
    [equipinfo] => Array
        (
            [cf_id] => 489
            [bi_num] => 
            [record_created] => 00-00-0000
            [region] => East
            [class] => SN
            [State_Tag] => M17891
            [Equip_Type] => PC
            [Brand] => HP
            [Model] => 6005 (SFF)
            [Serial_No] => MXL23200PY
            [Memory] => 
            [Prod_Key] => 
            [DOP] => 
            [Warranty] => 
            [Surplus_status] => a
            [Surplus_date] => 
            [Disposal_date] => 
        )

)


Note within the equipinfo array is class => SN. I've tried numerous ways of writing the php code. Here was my latest attempt:


<tr>
<td>Status: </td>
<td>
<?php
if ($form->data[$equipinfo['class']] ==  "SN")
{
    echo "State Network";
}else{
    echo "Not on state network";
}
?>


I'm evidently not getting the $form->data statement written correctly because I always get "Not on state network". How should this statement be formatted? I've also tried $form->data['equipinfo.class'] == "SN" but get the same results.

Thanks so much for your help.
Chris
chriso0258 23 Mar, 2015
I think I got it. Format should be:


if ($form->data[equipinfo]['class'] ==  "SN")
{
    echo "State Network";
}else{
    echo "Not on state network";
}
GreyHead 24 Mar, 2015
Hi Chris,

The format you need is $form->data['equipinfo']['class']

Your code will work OK if you only need to check the SN value; if you have multiple values to check I suggest that you use the 'Color array' example form the FAQ as your starting point.

Bob
This topic is locked and no more replies can be posted.