escapingsugarcrmcustom-code

Sugarcrm, custom buttons (as links to websites) in edit view of Accounts?


How to add custom html buttons opening 3rd party websites on clicks?

Followed some tutorials, but such code wont work for me:

        'customCode' => '{literal}<input id="Button" title="Button" class="button" type="button" name="Button" value="Some Button" onClick="window.open("http://google.com","","width=800,height=600");">{/literal}',
        'sugar_html' =>
          array (
            'type' => 'button',
            'value' => 'Button',
            'htmlOptions' =>
              array (
                'class' => 'button',
                'id' => 'Button',
                'title' => 'Button',
                'onclick' => 'window.open("http://google.com","","width=800,height=600");',
                'name' => 'Button',
              ),
          ),

It will split '' strings by ". Like http will be treated as input property! Tryied all sorts of character escapes, all they do is change what is treated as property and what as value. Not once I got that URL intact.


Solution

  • Pretty sure you're on the right track. Instead of this

    'customCode' => '{literal}<input id="Button" title="Button" class="button" type="button" name="Button" value="Some Button" onClick="window.open("http://google.com","","width=800,height=600");">{/literal}',

    Try this

    'customCode' => '{literal}<input id="Button" title="Button" class="button" type="button" name="Button" value="Some Button" onClick="window.open(\'http://google.com\',\'\',\'width=800,height=600\');">{/literal}',

    The difference being the mixed quotes... you had double quotes embedded in double quotes. Instead, use escaped single quotes inside of them.