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

<{$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 :
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 '$class '>' $extra '';
                    
$this->addElement($extra);
                } else {
                    
$extra '$class '> ';
                    
$this->addElement($extra);
                }
            
            }
            
        }


        function 
render()
        {

            if (
$xoopsModule->name() == 'oledrion')
            {
        
                
$ele_name $this->getName();
                
$ret '$ele_name '" id="' $ele_name '" action="' $this->getAction() . '" method="' $this->getMethod() . '" onsubmit="return xoopsFormValidate_' $ele_name '();"' $this->getExtra() . '>$this->getTitle() . '
';  
                
$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 '' NWLINE;
                
$ret .= $this->renderValidationJS(true);
                return 
$ret;
            }
    
        
            else
    
            {
        
                
$ele_name $this->getName();
                
$ret '$ele_name '" id="' $ele_name '" action="' $this->getAction() . '" method="' $this->getMethod() . '" onsubmit="return xoopsFormValidate_' $ele_name '();"' $this->getExtra() . '>
                    
                    
$this->getTitle() . '
                '
;
                
$hidden '';
                
$class 'even';
                foreach (
$this->getElements() as $ele) {
                    if (!
is_object($ele)) {
                        
$ret .= $ele;
                    } else if (!
$ele->isHidden()) {
                        if (!
$ele->getNocolspan()) {
                            
$ret .= '';
                            if ((
$caption $ele->getCaption()) != '') {
                                
$ret .= '. ($ele->isRequired() ? '-required' '') . '">';
                                
$ret .= '$caption ''
;
                                
$ret .= '*'
;
                                
$ret .= '
';
                            }
                            if ((
$desc $ele->getDescription()) != '') {
                                
$ret .= '$desc '
';
                            }
                            
$ret .= '$class '">' $ele->render() . '' NWLINE;
                        } else {
                            
$ret .= '';
                            if ((
$caption $ele->getCaption()) != '') {
                                
$ret .= '. ($ele->isRequired() ? '-required' '') . '">';
                                
$ret .= '$caption ''
;
                                
$ret .= '*'
;
                                
$ret .= '
';
                            }
                            
$ret .= '$class '" colspan="2">' $ele->render() . '';
                        }
                    } else {
                        
$hidden .= $ele->render();
                    }
                }
                
$ret .= '' NWLINE ' ' $hidden '' 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

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 '$ele_name '" id="' $ele_name '" action="' $this->getAction() . '" method="' $this->getMethod() . '" onsubmit="return xoopsFormValidate_' $ele_name '();"' $this->getExtra() . '>$this->getTitle() . '
';  
                
$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 '' 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
$sform = new XoopsThemeForm(_OLEDRION_PLEASE_ENTER"informationfrm"OLEDRION_URL.'checkout.php''post');
=>
$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.
-
The art of asking questions.

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

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 '$ele_name '" id="' $ele_name '" action="' $this->getAction() . '" method="' $this->getMethod() . '" onsubmit="return xoopsFormValidate_' $ele_name '();"' $this->getExtra() . '>$this->getTitle() . '
';  
                
$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 '' NWLINE;
                
$ret .= $this->renderValidationJS(true);
                return 
$ret;
        }
        
}



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

$sform = new XoopsThemeForm(adherents_utils::getModuleName().' - '._ADHERENTS_SEARCHFOR'productsSearchForm'ADHERENTS_URL.'search.php','post');

... replaced by
$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
require_once OLEDRION_PATH.'class/themeform.php';

The art of asking questions.

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

Login

Who's Online

428 user(s) are online (298 user(s) are browsing Support Forums)


Members: 0


Guests: 428


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits