This modifies files class.module.inc.php & modform.inc.php
From the standard library we have an assortment of form objects - form start, form end, radio button, input submit, input reset, etc.
We have something called CreateLink, to return a textual link to somewhere.
I wanted a button that didn't 'submit', didn't 'reset', but went to a specified href, and so in file class.module.inc.php I made something called CreateInputButton, which provides an onClick event.
As with other functions in this file, it's a wrapper for file modform.inc.php function called cms_module_CreateInputButton.
What does this give me?
It gives me a button, text or graphic. that goes to a particular href., rather than submit/reset.
For example:
the long way
$_link = $this->CreateLink($id, 'order', $returnid, $this->Lang('start_checkout_process'), array('perfaction'=>'request_ship_to_info'), '', TRUE) ;
$this->CreateInputButton($id, $name, $this->Lang('continue_checkout_process'), '', '', $_link );
the short way
$this->CreateInputButton($id, $name, $this->Lang('continue_checkout_process'), '', '',
$this->CreateLink($id, 'order', $returnid, $this->Lang('start_checkout_process'), array('perfaction'=>'request_ship_to_info'), '', TRUE));
In the long way, the link is creating seperately, then added to the new button parameter.
In the short way, the link generation is part of the parameter.
The way these end up is shown in the attached image.
The code used for these buttons is:
Checkout Button
$this->smarty->assign('startcheckout',
$this->CreateInputButton($id, $name, $this->Lang('continue_checkout_process'), '', '',
$this->CreateLink($id, 'order', $returnid, $this->Lang('start_checkout_process'), array('perfaction'=>'request_ship_to_info'), '', TRUE)));
Continue Shopping Button
$this->smarty->assign('continueshopping',
$this->CreateInputButton($id, $name, $this->Lang('continueshopping'), '', '',
$this->CreateLink($id, 'continueshopping', $returnid, '', array(returnid=>$returnid), '', TRUE)) );
The modification I made to the library files are:
class.module.inc.php
function CreateInputButton($id, $name, $value='', $image='', $addttext='', $url='')
{
$this->LoadFormMethods();
return cms_module_CreateInputButton($id, $name, $value, $image, $addttext, $url);
}
modform.inc.php
function cms_module_CreateInputButton($id, $name, $value='', $image='', $addttext='', $url='')
{
$id = cms_htmlentities($id);
$name = cms_htmlentities($name);
$text = '';
return $text . "\n";
}
Again, see the attached image for a couple of butons creating this way.
Fat Lizard
New button type
New button type
Last edited by fatlizard on Sun Jul 26, 2009 3:14 pm, edited 1 time in total.
Re: New button type
Thanks for this hint.
I always assigned the module id and the url to smarty and created the button "hardcoded" in the template instead of modifying the core.
But having this in the API would do many things much easier.
So this might be a feature request to the core i think, isn't it?
I always assigned the module id and the url to smarty and created the button "hardcoded" in the template instead of modifying the core.
But having this in the API would do many things much easier.
So this might be a feature request to the core i think, isn't it?
Re: New button type
Hello NaN,
Yes, it was a case of finding myself thinking "I wish it had ......", and it seemed to be a gap in the API ..
There was a button, there was a link generator, but not a combination of the two.
The only trouble with making core changes at the moment is to make sure any core files that are changed are backed up, so as not to be lost in any upgrade/restructuring.
I think it's a handy little addition, and will make things a little simpler along the track.
Whether it's added to distributions is for others to decide, however if anyone finds it handy then it's an interesting snippet to have in the arsenal.
Glad you find it of interest.
Fat Lizard
Yes, it was a case of finding myself thinking "I wish it had ......", and it seemed to be a gap in the API ..
There was a button, there was a link generator, but not a combination of the two.
The only trouble with making core changes at the moment is to make sure any core files that are changed are backed up, so as not to be lost in any upgrade/restructuring.
I think it's a handy little addition, and will make things a little simpler along the track.
Whether it's added to distributions is for others to decide, however if anyone finds it handy then it's an interesting snippet to have in the arsenal.
Glad you find it of interest.
Fat Lizard