1
Burning
How to customize a form created with XoopsThemeForm class ?
  • 2010/6/13 20:27

  • Burning

  • Theme Designer

  • Posts: 1163

  • Since: 2006/8/22


hi'

I have some difficulties (that's an euphemism) with Oledrion search form. I would like to customize it, and actually it works fine :

Resized Image



However to obtain this result I have to modify a Xoops class (I think it is the right word), into : www/class/xoopsform/themeform.php.

Why ? Because my original form is made with this 'class'. Here it is the only information that I have in module template about this form (oledrion_search.html) :
le="color: #000000"><?php <!-- Created by Instant Zero (http://www.instant-zero.com) --> <{$breadcrumb}> <br /> <{if $global_advert != ''}> <div align='center'><{$global_advert}></div> <br /> <{/if}> <{if $search_results}> <h2><{$smarty.const._OLEDRION_SEARCHRESULTS}></h2> <br /> <{foreach item=product from=$products}> <img src='<{$smarty.const.OLEDRION_IMAGES_URL}>product.png' alt='' border='0' />&nbsp;<b><a href="<{$product.link}>" title="<{$product.href_title}>"><{$product.title}></a></b><br /> <{/foreach}> <{if $pagenav !=''}><div style="text-align: right; margin: 10px;"><{$pagenav}></div><{/if}> <br /> <{/if}> <{$search_form}>


To recap : to modify <{$search_form}> I have to modify themeform.php file.




But if I do that, ALL my forms in Xoops administration are destroyed. This is a screenshot of System preferences :

Resized Image




I don't know how to create a specific template for Oledrion search engine, I mean how to customize <{$search_form}> without destroy all xoops forms


Some help / advice would be very welcome :) !
Still learning CSS and... english

2
ghia
Re: How to customize a form created with XoopsThemeForm class ?
  • 2010/6/14 0:00

  • ghia

  • Community Support Member

  • Posts: 4953

  • Since: 2008/7/3 1


Try with

if ($xoopsModule->name() == 'oledrion')
{
... your changed code
}
else
{
... the original code
}

3
Burning
Re: How to customize a form created with XoopsThemeForm class ?
  • 2010/6/14 0:45

  • Burning

  • Theme Designer

  • Posts: 1163

  • Since: 2006/8/22


hi' Ghia

Thanks for response :)

I have this error :
Quote:
Undefined variable: xoopsModule dans le fichier /class/xoopsform/themeform.php - ligne 52


Code modified is :
<?php defined('XOOPS_ROOT_PATH') or die('Restricted access'); xoops_load('XoopsForm'); class XoopsThemeForm extends XoopsForm { function insertBreak($extra = '', $class = '') { if ($xoopsModule->name() == 'oledrion') { $class = ($class != '') ? " class='" . preg_replace('/[^A-Za-z0-9ss_-]/i', '', $class) . "'" : ''; if ($extra) { $extra = '' . $class . '' . $extra . ''; $this->addElement($extra); } else { $extra = '' . $class . ''; $this->addElement($extra); } } else { $class = ($class != '') ? " class='" . preg_replace('/[^A-Za-z0-9ss_-]/i', '', $class) . "'" : ''; if ($extra) { $extra = '<tr><td colspan="2" ' . $class . '>' . $extra . '</td></tr>'; $this->addElement($extra); } else { $extra = '<tr><td colspan="2" ' . $class . '>&nbsp;</td></tr>'; $this->addElement($extra); } } } function render() { if ($xoopsModule->name() == 'oledrion') { $ele_name = $this->getName(); $ret = '<form name="' . $ele_name . '" id="' . $ele_name . '" action="' . $this->getAction() . '" method="' . $this->getMethod() . '" onsubmit="return xoopsFormValidate_' . $ele_name . '();"' . $this->getExtra() . '><div class="header-form">' . $this->getTitle() . '</div>'; $hidden = ''; $class = ''; foreach ($this->getElements() as $ele) { if (!is_object($ele)) { $ret .= $ele; } else if (!$ele->isHidden()) { if (!$ele->getNocolspan()) { $ret .= ''; if (($caption = $ele->getCaption()) != '') { $ret .= ''; $ret .= '' . $caption . ''; $ret .= ''; $ret .= ''; } if (($desc = $ele->getDescription()) != '') { $ret .= '' . $desc . ''; } $ret .= '' . $ele->render() . '' . NWLINE; } else { $ret .= ''; if (($caption = $ele->getCaption()) != '') { $ret .= ''; $ret .= '' . $caption . ''; $ret .= ''; $ret .= ''; } $ret .= '' . $ele->render() . ''; } } else { $hidden .= $ele->render(); } } $ret .= '' . NWLINE . ' ' . $hidden . '</form>' . NWLINE; $ret .= $this->renderValidationJS(true); return $ret; } else { $ele_name = $this->getName(); $ret = '<form name="' . $ele_name . '" id="' . $ele_name . '" action="' . $this->getAction() . '" method="' . $this->getMethod() . '" onsubmit="return xoopsFormValidate_' . $ele_name . '();"' . $this->getExtra() . '> <table width="100%" class="outer" cellspacing="1"> <tr><th colspan="2">' . $this->getTitle() . '</th></tr> '; $hidden = ''; $class = 'even'; foreach ($this->getElements() as $ele) { if (!is_object($ele)) { $ret .= $ele; } else if (!$ele->isHidden()) { if (!$ele->getNocolspan()) { $ret .= '<tr valign="top" align="left"><td class="head">'; if (($caption = $ele->getCaption()) != '') { $ret .= '<div class="xoops-form-element-caption' . ($ele->isRequired() ? '-required' : '') . '">'; $ret .= '<span class="caption-text">' . $caption . '</span>'; $ret .= '<span class="caption-marker">*</span>'; $ret .= '</div>'; } if (($desc = $ele->getDescription()) != '') { $ret .= '<div class="xoops-form-element-help">' . $desc . '</div>'; } $ret .= '</td><td class="' . $class . '">' . $ele->render() . '</td></tr>' . NWLINE; } else { $ret .= '<tr valign="top" align="left"><td class="head" colspan="2">'; if (($caption = $ele->getCaption()) != '') { $ret .= '<div class="xoops-form-element-caption' . ($ele->isRequired() ? '-required' : '') . '">'; $ret .= '<span class="caption-text">' . $caption . '</span>'; $ret .= '<span class="caption-marker">*</span>'; $ret .= '</div>'; } $ret .= '</td></tr><tr valign="top" align="left"><td class="' . $class . '" colspan="2">' . $ele->render() . '</td></tr>'; } } else { $hidden .= $ele->render(); } } $ret .= '</table>' . NWLINE . ' ' . $hidden . '</form>' . NWLINE; $ret .= $this->renderValidationJS(true); return $ret; } } } ?>


Is there something else to do, or error(s) ?
Still learning CSS and... english

4
Burning
Re: How to customize a form created with XoopsThemeForm class ?
  • 2010/6/14 1:17

  • Burning

  • Theme Designer

  • Posts: 1163

  • Since: 2006/8/22


I had a sudden inspiration (... called Dugris :)))) !

1. add global $xoopsModule; at the start
2. use if ($xoopsModule->dirname() == "oledrion") instead of if ($xoopsModule->name() == "oledrion")

Thanks
Still learning CSS and... english

5
ghia
Re: How to customize a form created with XoopsThemeForm class ?
  • 2010/6/14 7:19

  • ghia

  • Community Support Member

  • Posts: 4953

  • Since: 2008/7/3 1


Maybe a better way is to have a /modules/oledrion/class/themeform.php

<?php defined('XOOPS_ROOT_PATH') or die('Restricted access'); xoops_load('XoopsForm'); xoops_load('XoopsThemeForm'); class OledrionThemeForm extends XoopsThemeForm { function insertBreak($extra = '', $class = '') { $class = ($class != '') ? " class='" . preg_replace('/[^A-Za-z0-9ss_-]/i', '', $class) . "'" : ''; if ($extra) { $extra = '' . $class . '' . $extra . ''; $this->addElement($extra); } else { $extra = '' . $class . ''; $this->addElement($extra); } } function render() { $ele_name = $this->getName(); $ret = '<form name="' . $ele_name . '" id="' . $ele_name . '" action="' . $this->getAction() . '" method="' . $this->getMethod() . '" onsubmit="return xoopsFormValidate_' . $ele_name . '();"' . $this->getExtra() . '><div class="header-form">' . $this->getTitle() . '</div>'; $hidden = ''; $class = ''; foreach ($this->getElements() as $ele) { if (!is_object($ele)) { $ret .= $ele; } else if (!$ele->isHidden()) { if (!$ele->getNocolspan()) { $ret .= ''; if (($caption = $ele->getCaption()) != '') { $ret .= ''; $ret .= '' . $caption . ''; $ret .= ''; $ret .= ''; } if (($desc = $ele->getDescription()) != '') { $ret .= '' . $desc . ''; } $ret .= '' . $ele->render() . '' . NWLINE; } else { $ret .= ''; if (($caption = $ele->getCaption()) != '') { $ret .= ''; $ret .= '' . $caption . ''; $ret .= ''; $ret .= ''; } $ret .= '' . $ele->render() . ''; } } else { $hidden .= $ele->render(); } } $ret .= '' . NWLINE . ' ' . $hidden . '</form>' . NWLINE; $ret .= $this->renderValidationJS(true); return $ret; } } ?>
(To you to test.)

In Oledrion, everywhere an XoopsThemeForm is used, it has to be renamed to OledrionThemeForm and the /modules/oledrion/class/themeform.php included.
eg in checkout.php
le="color: #000000"><?php $sform = new XoopsThemeForm(_OLEDRION_PLEASE_ENTER, "informationfrm", OLEDRION_URL.'checkout.php', 'post');
=>
le="color: #000000"><?php $sform = new OledrionThemeForm(_OLEDRION_PLEASE_ENTER, "informationfrm", OLEDRION_URL.'checkout.php', 'post');

Advantage are that
- the core stays unmodified.
- the differences are transparent and obvious.
- installing Oledrion in an other directory (cloning) doesn't need adaptation.
-

6
Burning
Re: How to customize a form created with XoopsThemeForm class ?
  • 2010/6/14 7:27

  • Burning

  • Theme Designer

  • Posts: 1163

  • Since: 2006/8/22


hi Ghia,

This would be a real step forward for the module ! I test it as soon as possible :)
Still learning CSS and... english

7
Burning
Re: How to customize a form created with XoopsThemeForm class ?
  • 2010/6/15 11:10

  • Burning

  • Theme Designer

  • Posts: 1163

  • Since: 2006/8/22


hi'

This hack is too difficult for me, I'm not able to implement it (blank pages...)

What I have done :


1. Add a specific class for Oledrion in class/xoopsform/themeform.php

le="color: #000000"><?php class OledrionThemeForm extends XoopsThemeForm { function insertBreak($extra = '', $class = '') { $class = ($class != '') ? " class='" . preg_replace('/[^A-Za-z0-9ss_-]/i', '', $class) . "'" : ''; if ($extra) { $extra = '' . $class . '' . $extra . ''; $this->addElement($extra); } else { $extra = '' . $class . ''; $this->addElement($extra); } } function render() { $ele_name = $this->getName(); $ret = '<form name="' . $ele_name . '" id="' . $ele_name . '" action="' . $this->getAction() . '" method="' . $this->getMethod() . '" onsubmit="return xoopsFormValidate_' . $ele_name . '();"' . $this->getExtra() . '><div class="header-form">' . $this->getTitle() . '</div>'; $hidden = ''; $class = ''; foreach ($this->getElements() as $ele) { if (!is_object($ele)) { $ret .= $ele; } else if (!$ele->isHidden()) { if (!$ele->getNocolspan()) { $ret .= ''; if (($caption = $ele->getCaption()) != '') { $ret .= ''; $ret .= '' . $caption . ''; $ret .= ''; $ret .= ''; } if (($desc = $ele->getDescription()) != '') { $ret .= '' . $desc . ''; } $ret .= '' . $ele->render() . '' . NWLINE; } else { $ret .= ''; if (($caption = $ele->getCaption()) != '') { $ret .= ''; $ret .= '' . $caption . ''; $ret .= ''; $ret .= ''; } $ret .= '' . $ele->render() . ''; } } else { $hidden .= $ele->render(); } } $ret .= '' . NWLINE . ' ' . $hidden . '</form>' . NWLINE; $ret .= $this->renderValidationJS(true); return $ret; } }



2. Modify call to form class in one single file oledrion/include/product_search_form.php

le="color: #000000"><?php $sform = new XoopsThemeForm(adherents_utils::getModuleName().' - '._ADHERENTS_SEARCHFOR, 'productsSearchForm', ADHERENTS_URL.'search.php','post');

... replaced by
le="color: #000000"><?php $sform = new OledrionThemeForm(adherents_utils::getModuleName().' - '._ADHERENTS_SEARCHFOR, 'productsSearchForm', ADHERENTS_URL.'search.php','post');



... not sure that's a great improvment for Xoops , but it works :
- oledrion search form is displayed as I want
- other oledrion forms are not modified

Still learning CSS and... english

8
ghia
Re: How to customize a form created with XoopsThemeForm class ?
  • 2010/6/15 12:18

  • ghia

  • Community Support Member

  • Posts: 4953

  • Since: 2008/7/3 1


With me, it works also if you save part 1 in a /modules/oledrion/class/ themeform.php (with starting <?php and end brackets) and in part 2 add a
le="color: #000000"><?php require_once OLEDRION_PATH.'class/themeform.php';


9
Burning
Re: How to customize a form created with XoopsThemeForm class ?
  • 2010/10/9 20:05

  • Burning

  • Theme Designer

  • Posts: 1163

  • Since: 2006/8/22


hi'

It works now (4 months later ).
As Ghia said (thanks again !), no use to hack Xoops.

So to be able to customize Oledrion search form :

1 • create a file called themeform.php
2 • put it into www/modules/oledrion/class/
3 • copy inside all the code given by Ghia (post : 2010/6/14 8:19:57)
4 • copy this line into www/modules/oledrion/include/product_search_form.php
Quote:

require_once XOOPS_ROOT_PATH.'/class/xoopsformloader.php';
// addition
require_once OLEDRION_PATH.'class/themeform.php';
// end
require_once OLEDRION_PATH.'class/tree.php';
Still learning CSS and... english