Jump to content
cupidare

Frozen: tep_draw_button problem

Recommended Posts

Hello, 

recently I have a problem with buttons (since updating to frozen and php 7.1). 

when I define a button without specifying  the type the following strange thing appears in function tep_draw_button()

 

// Output a jQuery UI Button
  function tep_draw_button($title = null, $icon = null, $link = null, $priority = null, $params = null, $style = null) {
    static $button_counter = 1;
    $types = array('submit', 'button', 'reset');
    if ( !isset($params['type']) ) {
      $params['type'] = 'submit';
      //here the value assignment is "s" instead of "submit"
    }
 

And therefore the buttons don't work with a link. Has anyone a hint?

Share this post


Link to post
Share on other sites

Not sure what you're trying to do but with Bootstrap you have 4 possibilities to create a button. See here for further info.

If you want to have a button that has a link to go somewhere then you could use the first example.

<a class="btn btn-default" href="#" role="button">Link</a>

But it should be possible to do with tep_draw_button as well though.

<?php echo tep_draw_button(BUTTON_TEXT, 'fas fa-chevron-right', tep_href_link('index.php')); ?>

 

Edited by Tsimi

Share this post


Link to post
Share on other sites

Hello @Tsimi

Thank you for your reply. Your way of button creation normally works for me. I want the following button

tep_draw_button('call me', 'fa fa-lg fa-phone', "tel:0049XXXXXX", '', '', 'btn-info') 

The button itself appears, but it doesn't work (the link is missing). The re-definition of the button (None -> to "submit") just defines to "s" instead to "submit"

 

EDIT:

It works only when using Null instead of "" (empty). Is this something new?

Edited by cupidare

Share this post


Link to post
Share on other sites

If possible you should always use NULL instead of ' '. In this case you're right it only works with NULL. 

Edited by Tsimi

Share this post


Link to post
Share on other sites

It is definetly a new behaviour. I used also some addons which also define the button with ' ' instead of Null... Is it a "problem" with php?

Share this post


Link to post
Share on other sites

Not sure since when that is the case. I just tested it in an older EDGE shop and the same things happens there.
Not sure if it is PHP related or not. But I guess as long it works with NULL it's OK.

Share this post


Link to post
Share on other sites

What is the purpose of the button? You have "'call me' as the text for the button but then you have the telephone number: "tel:0049XXXXXX". If this worked, what would want to display on the site?

Share this post


Link to post
Share on other sites
3 hours ago, cupidare said:


tep_draw_button('call me', 'fa fa-lg fa-phone', "tel:0049XXXXXX", '', '', 'btn-info') 

You have several add-ons already available to provide this function on frozen and CE, This is just one of a number available.

Edited by JcMagpie

 

Share this post


Link to post
Share on other sites

@TsimiThanks for the explanation.

@cupidareThe following may work, though I haven't tested it.

tep_draw_button('call me', 'fa fa-lg fa-phone', 'tel:0049XXXXXX"', 'primary', array('type'=>'button'), 'btn-info');

 

Share this post


Link to post
Share on other sites

That's one of those cases where the PHP maintainers are going around tightening up their code to better match the published specs. This often means that site code that worked before suddenly stopped working... technically it was invalid (sloppy coding) in the first place, but no one complained (until now). I wouldn't be surprised to see this problem popping up here and there in any PHP code, including osC.

Share this post


Link to post
Share on other sites

hi all, @cupidare  @Tsimi  @MrPhil  @Jack_mcs  @JcMagpie

on my 234.1 BS (Edge) version, I install @Jack_mcs Jack's MATC modules, and have error message:

Warning: Illegal string offset 'type'
in /catalog/includes/functions/html_output.php on line 486

 $params['type'] = 'submit';


Warning: Illegal string offset 'type'
in /catalog/includes/functions/html_output.php on line 489
Warning: Illegal string offset 'type'

if ( !in_array($params['type'], $types) ) {


in /catalog/includes/functions/html_output.php on line 490
Warning: Illegal string offset 'type'

$params['type'] = 'submit';


in /catalog/includes/functions/html_output.php on line 493
Warning: Illegal string offset 'type'

if ( ($params['type'] == 'submit') && isset($link) ) {


in /catalog/includes/functions/html_output.php on line 503
Warning: Illegal string offset 'type'

if ( ($params['type'] == 'button') && isset($link) ) {


in /catalog/includes/functions/html_output.php on line 511
Warning: Illegal string offset 'type'

$button .= ' type="' . tep_output_string($params['type']) . '"';


in /catalog/includes/functions/html_output.php on line 530

if ( ($params['type'] == 'button') && isset($link) ) {

any advice what I should to do make the errors go away?

Many thanks!  Lyn
 

Share this post


Link to post
Share on other sites

The problem is with the php version you are using. The add-on is not compatiable with the version you are using. I'm sure this has already been coverd in this forum.

You need to check that your key exists in the array or not, instead of simply trying to access it. The solution is to use the "isset"

Replace:

$myVar = $someArray['someKey']

With something like:

if (isset($someArray['someKey'])) {
    $myVar = $someArray['someKey']
}

 

Share this post


Link to post
Share on other sites

The problem is that $params was apparently not designated as an array, but is a scalar (such as a string). Older PHP versions would simply promote $params to an array (or do something similar) and do the array assignment. If $params is locally created, check that it uses array(). If it's passed in from elsewhere, you will need to figure out why it is a scalar and not an array.

The error message says "illegal string offset", which leads me to believe that $params is a scalar string.

Share this post


Link to post
Share on other sites

hi all,

thank you for reply. Sorry I google and this one comes up, and i stuck with tep_draw_button function codes, so thought it should be related, wrong judgement 😭

Yes I also found the other post from forums but it only mentioned php version, and I dont quite understand the solution.

Thank you @JcMagpie Zahid for the example and thank you @MrPhil Phil for the explanation.

Once again, thank you!  Lyn

Share this post


Link to post
Share on other sites

@ce7Try this. In includes/functions/html_output.php, fine


    $types = array('submit', 'button', 'reset');

    if ( !isset($params['type']) ) {
      $params['type'] = 'submit';
    }

and change it to

    if ( !isset($params['type']) ) {
      $params = array('type' => '');
      $params['type'] = 'submit';
    }

 

Share this post


Link to post
Share on other sites
On 8/12/2018 at 5:00 PM, Jack_mcs said:

@TsimiThanks for the explanation.

@cupidareThe following may work, though I haven't tested it.


tep_draw_button('call me', 'fa fa-lg fa-phone', 'tel:0049XXXXXX"', 'primary', array('type'=>'button'), 'btn-info');

 

@Jack_mcs

I'm trying to get a "newwindow" with tep_draw_button function but I failed to make it :

      if ( isset($params['newwindow']) ) {
        $button .= ' target="_blank"';
      }

Do you know how to get it ?


Osc v2.3.4 BS "custom"
PHP 7.3 compatible (710 modified files => o_O')

Share this post


Link to post
Share on other sites

I think this will work

echo tep_draw_button(IMAGE_BUTTON_CONTINUE, 'fa fa-angle-right', tep_href_link('index.php'), null, array('type'=>'button','newwindow'=>'1'), null );

 

Share this post


Link to post
Share on other sites
3 minutes ago, Jack_mcs said:

I think this will work


echo tep_draw_button(IMAGE_BUTTON_CONTINUE, 'fa fa-angle-right', tep_href_link('index.php'), null, array('type'=>'button','newwindow'=>'1'), null );

 

Thank you, it works !
NB: I've just found the same writing 'newwindows'=>'1' just 3 secondes before your reply but many thanks for your speed. ^^
 


Osc v2.3.4 BS "custom"
PHP 7.3 compatible (710 modified files => o_O')

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×