The Joomla! Forum ™



Forum rules


Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.



Post new topic Reply to topic  [ 16 posts ] 
Author Message
PostPosted: Thu Jan 13, 2011 12:00 am 
Joomla! Fledgling
Joomla! Fledgling

Joined: Fri May 19, 2006 3:45 am
Posts: 1
The new security feature of specifying available and allowed form fields is quite nice and it's definitely going to help keep hackers from exploiting sites. But sometimes there are situations where one would like to override certain fields at the template level. Is it possible?

Here's a scenario:
I create a new template. In it, I am displaying some additional fields within /templates/mytemplate/html/com_content/form/edit.php so my administrators who log in to the front end of the site can control additional parameters for articles ("created" and "created_by", for example). Simply adding them to the override file displays them, but because /components/com_content/models/forms/article.xml has filter="unset" for each of these and lacks proper label, description and other attributes, the adaptability seems to stop there.

In a 1.5 template, because this security procedure wasn't in place, it was easy to simply add in missing fields and the logic to support them. But 1.6 seems to present a new challenge.

Given that example...
    Can you specify an override XML file for forms so the core doesn't have to be hacked? Or does this defeat the purpose?
    Where would this need to be placed within the template package if it is an option?
    What would be a good alternative if this isn't an option?

Thanks in advance!


Top
 Profile  
 
PostPosted: Thu Jan 13, 2011 10:13 pm 
User avatar
Joomla! Ace
Joomla! Ace

Joined: Fri Sep 22, 2006 6:22 pm
Posts: 1823
Location: UK
Yes, Id like to know how to do this too. I havent tried putting a modified ( for example ) registration.xml in /templates/<template>/com_users/register/
Ill probably try it tomorrow

_________________
EmailAsUsername - Remove Usernames Joomla! Virtuemart And JomSocial registration http://www.lunarhotel.co.uk Many other extensions supported.
RsJoomla! RsForms RsMembership http://www.lunarhotel.co.uk/rsjoomla.php


Top
 Profile  
 
PostPosted: Thu Jan 13, 2011 10:17 pm 
User avatar
Joomla! Ace
Joomla! Ace

Joined: Fri Sep 22, 2006 6:22 pm
Posts: 1823
Location: UK
Curiosity got the better of me. No that didnt work. Im looking to remove some fields from the xml file. I could just tell the template not to display a specific field, but that seems a bit messy.

_________________
EmailAsUsername - Remove Usernames Joomla! Virtuemart And JomSocial registration http://www.lunarhotel.co.uk Many other extensions supported.
RsJoomla! RsForms RsMembership http://www.lunarhotel.co.uk/rsjoomla.php


Top
 Profile  
 
PostPosted: Thu Jan 13, 2011 10:21 pm 
User avatar
Joomla! Ace
Joomla! Ace

Joined: Fri Sep 22, 2006 6:22 pm
Posts: 1823
Location: UK
doesnt work putting into /templates/<template name>/xml/com_user/registration either... hmmmm....

_________________
EmailAsUsername - Remove Usernames Joomla! Virtuemart And JomSocial registration http://www.lunarhotel.co.uk Many other extensions supported.
RsJoomla! RsForms RsMembership http://www.lunarhotel.co.uk/rsjoomla.php


Top
 Profile  
 
PostPosted: Fri Jan 14, 2011 8:09 am 
User avatar
Joomla! Ace
Joomla! Ace

Joined: Fri Sep 22, 2006 6:22 pm
Posts: 1823
Location: UK
Ok, well Ive got a solution, as to whether its the "correct" way is still unknown.

So we know we can override output still, by using the normal template override feature. For me, Im trying to override the login page. So, Im taking a copy of /components/com_users/views/login/tmpl/default.php and putting it into /templates/beez_20/html/com_users/login.

So far so 1.5.

Now take a copy of /components/com_users/models/forms/login.xml and place in /templates/beez_20/html/com_users/login as well

now edit /templates/beez_20/html/com_users/login/default.php and add at the top of the form (I added mine just after the form tag) the following commands:

Code:
$this->form->reset( true ); // to reset the form xml loaded by the view
   $this->form->loadFile( dirname(__FILE__) . DS . "login.xml"); // to load in our own version of login.xml


Then you can safely edit /templates/beez_20/html/com_users/registration/registration.xml

_________________
EmailAsUsername - Remove Usernames Joomla! Virtuemart And JomSocial registration http://www.lunarhotel.co.uk Many other extensions supported.
RsJoomla! RsForms RsMembership http://www.lunarhotel.co.uk/rsjoomla.php


Top
 Profile  
 
PostPosted: Wed Jan 19, 2011 8:59 pm 
Joomla! Enthusiast
Joomla! Enthusiast

Joined: Wed Mar 03, 2010 7:58 pm
Posts: 175
@bizzynate

No, you cannot add additional fields for an article the way you are thinking (automatically). The edit.php doesn't echo the whole form, only the default fields for an article and metadata params. You can tell your edit.php file to echo those if you'd like but it would get messy as you would have to change the model class for com_content.

Yes, you CAN over ride the values of the fields at the article. You need to create an alternate layout. Copy and paste edit.php into the same folder and rename it to something else.

From there you need to tell JForm to load your new file path for your form and then the fields will be available. You can also put an .xml file in the folder and define the new settings there, but at some point you need to manually echo the params to the page. You can echo all fieldsets in your new .xml file... go to the docs to learn how to over-ride default fields from alternate layouts.

See the problem is, when you create a new menu item, your new layout will appear lol. There are several ways of doing things but, by default, its one or the other (alternate layout or alternate menu item). If you have an .xml file in your folder (say newform.xml) and your new alternate layout is named (newform.php), your alternate layout option will not show up (at the config options for that item). Its kinda messy.


Top
 Profile  
 
PostPosted: Fri Mar 25, 2011 1:40 am 
Joomla! Apprentice
Joomla! Apprentice

Joined: Sun Feb 24, 2008 4:47 am
Posts: 9
"dylanjh" provided the best answer, however I found that doing that with com_content in admin caused problems. Specifically, the whole form would be "reset", meaning that any data already loaded would be lost - the form would always be empty even when it shouldn't be. Also, the form data wasn't getting saved in the database, since Joomla was automatically loading the (non-custom) article.xml file while doing a save()

An alternate solution, that works for com_content in admin console:
1) Copy /administrator/components/com_content/models/forms/article.xml to /administrator/templates/YOUR_ADMIN_TEMPLATE_NAME/html/com_content/article/article.xml
2) Copy /administrator/components/com_content/views/article/tmpl/edit.php to /administrator/templates/YOUR_ADMIN_TEMPLATE_NAME/html/com_content/article/edit.php
3) Create your own custom Joomla Plugin. It must be a "system" plugin. Inside your plugin add this function:
function onAfterRoute() {
jimport('joomla.form.form');
JForm::addFormPath(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_content/models/forms');
JForm::addFormPath(JPATH_ADMINISTRATOR.'/templates/bluestork/html/com_content/article');
}

NOTE: you should change "/templates/bluestork/" above to the path to your admin template, if it's something other than 'bluestork'
4) Install your system plugin and ensure it is enabled
5) Customise both custom files: edit.php and article.xml as necessary. NOTE that if you're just adding basic parameters, all you need to do is add those parameters to article.xml under the '<fields name="attribs">' section.... however if you're adding an extra 'big' custom field (like a text editor), you'll need to edit both article.xml (under the first fieldset), ** AND ** add the custom field to your edit.php file, ** AND ** add the extra field to the end of your 'jos_content' database table (using PhpMyAdmin or similar)


Top
 Profile  
 
PostPosted: Mon May 09, 2011 6:48 pm 
Joomla! Fledgling
Joomla! Fledgling

Joined: Mon May 09, 2011 6:41 pm
Posts: 2
The approach I am taking is to use the onContentPrepareForm event to inject custom fields into the Form as it's being loaded. This is triggered during the Model initialization, so it should occur during administrative functions like editing the article. As long as you are storing your custom attributes either in attribs or metadata, they should be available to your front-end.


Top
 Profile  
 
PostPosted: Tue Nov 08, 2011 6:59 pm 
Joomla! Intern
Joomla! Intern

Joined: Tue Dec 29, 2009 5:35 am
Posts: 52
davidbalt wrote:
The approach I am taking is to use the onContentPrepareForm event to inject custom fields into the Form as it's being loaded. This is triggered during the Model initialization, so it should occur during administrative functions like editing the article. As long as you are storing your custom attributes either in attribs or metadata, they should be available to your front-end.


I did some searching to try and figure out exactly how you did this and I found this official Joomla tutorial which actually shows how to write a simple profile plugin using the same approach:

http://docs.joomla.org/Creating_a_profile_plugin


Top
 Profile  
 
PostPosted: Sun Nov 20, 2011 10:10 am 
Joomla! Apprentice
Joomla! Apprentice

Joined: Tue Jan 22, 2008 8:09 pm
Posts: 28
I had a lot of trouble getting the 'onContentPrepareForm' approach to work. Fx. it seems that the
$form->loadFile has changed to
$form->load();

I finaly got my fields in, but couldn't make it save any of them.

However the solution GavinGrup showed directly out of the box. Thanks! This was the last joomla part which we haven't been able to override :)

_________________
Signature forum rules: viewtopic.php?f=8&t=65


Top
 Profile  
 
PostPosted: Mon Nov 21, 2011 6:31 pm 
Joomla! Fledgling
Joomla! Fledgling

Joined: Mon May 09, 2011 6:41 pm
Posts: 2
You're correct that saving is a challenge. I gave myself the limitation that I would not modify any system files nor would I change what is stored in the system tables. I wanted to write a new component that could be installed and uninstalled without contaminating the rest of the system, but would still add additional metadata to articles. My onContentPrepareForm approach has this advantage. I define an XML form that extends the com_content default form using a plugin, the load() method mentioned elsewhere. I then have a validation rule on that form field. This validation rule is actually responsible for all of the logic, including saving the information to the database. It's backwards and awkward, but nothing I do touches any existing files and it's all totally atomic, both in terms of files and in terms of database information.


Top
 Profile  
 
PostPosted: Wed Dec 14, 2011 9:59 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Sat Jun 25, 2011 12:25 am
Posts: 7
very useful, I used the onContentPrepareForm method and it works better than including the intended xml.
Works on 1.7.3 perfectly so far.

Thank you.


Top
 Profile  
 
PostPosted: Tue Feb 07, 2012 12:41 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Tue Feb 07, 2012 12:20 pm
Posts: 9
Location: istanbul
http://docs.joomla.org/Creating_a_profile_plugin[/quote]


usefull content , i got it thanks


Top
 Profile  
 
PostPosted: Wed Apr 18, 2012 6:17 am 
User avatar
Joomla! Enthusiast
Joomla! Enthusiast

Joined: Mon Oct 10, 2005 7:09 am
Posts: 213
Location: Payyannur, Kannur, Kerala,India
@gavingrubb, @dylanjh
Thanks to both of you.

"gavingrubb" solution worked wonderfully well on my home machine but when I tried the same on my workstation at office, it didnt. After trying on a fresh installation and not finding it work , thought about trying the same following "dylanjh" approach.

"gavingrubb" mentioning about form data not loaded is true but the below worked :-
Code:
  //$this->form->reset( true ); // to reset the form xml loaded by the view
    $this->form->loadFile( dirname(__FILE__) . DS . "article.xml");


The only issue is that its not able to save the custom field to database. I request some advice on this. thanks in advance

Regards

hbmarar

_________________
Technology to Solutions ( Skype : holy.geek_saffrongeek )
Given enough eyeballs , All bugs are shallow.
Collecting data is only the first step toward wisdom. But sharing data is the first step toward community


Top
 Profile  
 
PostPosted: Sun Dec 29, 2013 12:17 pm 
Joomla! Fledgling
Joomla! Fledgling

Joined: Sun Dec 29, 2013 12:14 pm
Posts: 2
Hi there!

I'm also trying to override the 'administrator/components/models/forms/article.xml' by folowing the gavingrubb method.

But I didn't how to modify the edit.php file....

Someone could tell me how to add the custum fields in it?

Thanks a lot!


Top
 Profile  
 
PostPosted: Wed Jan 08, 2014 12:16 pm 
Joomla! Fledgling
Joomla! Fledgling

Joined: Sun Dec 29, 2013 12:14 pm
Posts: 2
Up ;)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 16 posts ] 



Who is online

Users browsing this forum: No registered users and 18 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group