This topic is locked

Using a custom field

10/8/2011 2:43:17 PM
PHPRunner General questions
C
cynic author

When using the custom field, is there any way to output an image based on the fields value?
For example, I have;

$testimage = "<img src=\"plus.gif\">";
if($table=="dbo.pgnTEST" && $field=="testfield")

{

if ($value == '0') $value = $testimage;

if ($value == '1') $value = 'No Image!';

;}


How can I get this to output an image instead of just the text?

C
cgphp 10/9/2011
if($table=="dbo.pgnTEST" && $field=="testfield")

{

if ($value == '0')

$value = "<img src=\"plus.gif\" />";

else

$value = 'No Image!';

}


What do you mean by "How can I get this to output an image instead of just the text?"

If the if statement is correct you should see the plus.gif image. Check if the path to the image exist.

C
cynic author 10/9/2011


if($table=="dbo.pgnTEST" && $field=="testfield")

{

if ($value == '0')

$value = "<img src=\"plus.gif\" />";

else

$value = 'No Image!';

}


What do you mean by "How can I get this to output an image instead of just the text?"

If the if statement is correct you should see the plus.gif image. Check if the path to the image exist.


I can echo the image so I know the path is correct. The problem is that if I echo or print the image it appears at the top of the page instead of in the grid view.
The above code simply displays the text value of <img src=\"plus.gif\" /> in the table view.

C
cgphp 10/9/2011

The above code simply displays the text value of <img src=\"plus.gif\" /> in the table view.


mmmm...please, post a screenshot of what you see.

S
stiven 10/10/2011

are you using custom view in the field you want the image to be printed???

you may wanna try this..


$info = $data['testfield']; // get the value of the field assuming the field name is 'testfield'
if ($info == "0") // if the value is 0 assign image



$fvalue = "<img src=\"plus.gif\" />";
}
else if ($info == "1"){ // if value is 1 assign text no image



$fvalue = 'No Image!';

}
$value = $fvalue;
C
cynic author 10/19/2011



are you using custom view in the field you want the image to be printed???

you may wanna try this..


$info = $data['testfield']; // get the value of the field assuming the field name is 'testfield'
if ($info == "0") // if the value is 0 assign image
$fvalue = "<img src=\"plus.gif\" />";
}
else if ($info == "1"){ // if value is 1 assign text no image
$fvalue = 'No Image!';

}
$value = $fvalue;



Thanks for the option but it still just shows the text instead of the actual image. The field type is set to custom;



$fdata = array();

$fdata["strName"] = "testfield";

$fdata["ownerTable"] = "dbo.testfield";

$fdata["Label"]="Test_Field";
$fdata["FieldType"]= 3;



$fdata["UseiBox"] = false;



$fdata["EditFormat"]= "Text field";

$fdata["ViewFormat"]= "Custom";
$fdata["NeedEncode"]=true;



$fdata["GoodName"]= "Test_Field";

$fdata["FullName"]= "dbo.pgntest.testfield";



$fdata["Index"]= 14;

$fdata["EditParams"]="";



$fdata["bListPage"]=true;



//Begin validation

$fdata["validateAs"] = array();

$fdata["validateAs"]["basicValidate"][] = getJsValidatorName("Number");



//End validation

$fdata["FieldPermissions"]=true;

$tdatatest["Test_Field"]=$fdata;
C
cgphp 10/19/2011

Please, remove the actual code in the Custom field and enter only the following statement:

$value = "<img src=\"plus.gif\">";