Forums: [SOLVED] Echo html from custom field - Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

[SOLVED] Echo html from custom field Rate Topic: -----

#1 User is offline   Kristian Karlsson 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 79
  • Joined: 02-November 09

Posted 24 November 2017 - 09:27 AM

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
0

#2 User is offline   admin 

  • Administrator
  • PipPipPip
  • Group: Admin
  • Posts: 15497
  • Joined: 03-February 03

Posted 24 November 2017 - 11:37 PM

In 'View as' Custom you should assign value to $value variable instead of echoing it.
Best regards,
Sergey Kornilov
0

#3 User is offline   Kristian Karlsson 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 79
  • Joined: 02-November 09

Posted 25 November 2017 - 10:33 AM

View Postadmin, on 25 November 2017 - 12:37 AM, said:

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.
0

#4 User is offline   romaldus 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 450
  • Joined: 19-May 08

Posted 25 November 2017 - 03:38 PM

You cannot use "view as" custom in add /edit page or input forms.
View as custom works in list, view, and print page
Freelance Programmer | Photographer
0

#5 User is offline   Kristian Karlsson 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 79
  • Joined: 02-November 09

Posted 26 November 2017 - 10:43 AM

View Postromaldus, on 25 November 2017 - 04:38 PM, said:

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 :)

I changed so i'm using an php codes snippet instead.

Thanks!
0

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic