This topic is locked
[SOLVED]

 Echo html from custom field

11/24/2017 4:27:08 AM
PHPRunner General questions
S
snuffi01 author

Hi,

Hope anyone can guide me how to be able to echo out html from an db field set to view as "custom"
I'm using an javascript switch to make an ordinary input checkbox look like an iPhone switch.

When i echo out my input via "php code snippet" it works as expected, as example i can do it like this:



require_once ("saresources/included_files/sa_api2.php");

$data['extension_id'] = $_SESSION["extension_id"];

$api = new sa_api_wg();

$json = $api->post('api/shoretel/get_extension_status', $data);
$userwgstate = $json->workgroup_state;
if ($userwgstate == 1)

{

echo '<INPUT class="js-switch special js-check-change" data-action="set_extension_workgroup_state" style="display: block !important;" type="checkbox" checked>';
}

elseif ($userwgstate == 2)

{

echo '<INPUT class="js-switch special js-check-change" data-action="set_extension_workgroup_state" style="display: block !important;" type="checkbox" checked>';
}

else {

echo '<INPUT class="js-switch special js-check-change" data-action="set_extension_workgroup_state" style="display: block !important;" type="checkbox">';

}



But i need to be able to use same approach on an db field, my idea is to just do it in "custom".

My field on my edit page is called "enable_menu"

The code for custom that i'm trying:



global $data;

if ($value["enable_menu"] = 'f')

{

echo '<INPUT class="js-switch special js-check-change" data-action="set_extension_enable_menu" style="display: block !important;" type="checkbox">';
}

elseif ($value["enable_menu"] == 't')

{

echo '<INPUT class="js-switch special js-check-change" data-action="set_extension_enable_menu" style="display: block !important;" type="checkbox" checked>';
}

else {

echo = '<INPUT class="js-switch special js-check-change" data-action="set_extension_enable_menu" style="display: block !important;" type="checkbox" checked>';

}


Problem is that the page is generated as an ordinary input checkbox and not the above input with class.

(Also tried above code but with $data = '....', with same result.

Does anyone know if its possible to do what i want or do i have to use an "php code snippet" ?
/ Kristian

admin 11/24/2017

In 'View as' Custom you should assign value to $value variable instead of echoing it.

S
snuffi01 author 11/25/2017



In 'View as' Custom you should assign value to $value variable instead of echoing it.


Have tried to use $value but all i get is an text input with field value in text.

Not even when i just try this it does work.



$value = '<INPUT class="js-switch special js-check-change" data-action="set_extension_enable_menu" style="display: block !important;" type="checkbox" checked>';



From above the genrated page look like this:

Image
Also tried with this custom code:



global $data;

if ($data["enable_menu"] = 'f')

{

$value = '<INPUT class="js-switch special js-check-change" data-action="set_extension_enable_menu" style="display: block !important;" type="checkbox">';
}

elseif ($data["enable_menu"] = 't')

{

$value = '<INPUT class="js-switch special js-check-change" data-action="set_extension_enable_menu" style="display: block !important;" type="checkbox" checked>';
}

else {

$value = '<INPUT class="js-switch special js-check-change" data-action="set_extension_enable_menu" style="display: block !important;" type="checkbox" checked>';

}



Above still just gives me an text field as in image above.

My underlying database is postgres if that can have anything to do with the problem.

romaldus 11/25/2017

You cannot use "view as" custom in add /edit page or input forms.

View as custom works in list, view, and print page

S
snuffi01 author 11/26/2017



You cannot use "view as" custom in add /edit page or input forms.

View as custom works in list, view, and print page


That explain my problem <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=83803&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' />
I changed so i'm using an php codes snippet instead.
Thanks!