Two Joomla questions on custom fields

Posted on 2010-08-16
Last Modified: 2013-12-13
Hi, all.  I'm a newbie to joomla and have run into a couple of problems with custom fields.

Using the guidelines found at (working solution is at bottom of page 2) I have successfully added several custom fields to a joomla site.  They display and update fine.  Now, I need to do 2 other things and can't figure them out:
1) Add data validation when a new article is added.
2) Convert 3 of the text boxes to select lists.

1) Page /libraries/joomla/database/table/content.php has a function named "Check()" that appears to validate the other (standard) article fields. Example:
if(empty($this->title)) {
$this->setError(JText::_('Article must have a title'));
return false;
However, if I edit the function by copying this code and changing the field name ("title") to one of my custom fields ("url"), I get a 500 error if "url" is left blank. This tells me the test is working but "setError" is not doing what I expected.  I'd like to use the same "alert" type validation that joomla uses, but how do I add?

2) Working on /administrator/components/com_content/admin.content.html.php, three of the new fields need to be changed from text boxes to select lists.  The values to include in the list of options are in tables in the joomla database.  When I try to make a new connection to the db to run the query, I get "Error Loading Modules" message at the top of the page and, in the "Parameters" area, the following error message:
Warning: Invalid argument supplied for foreach() in [*site root removed*]/libraries/joomla/html/html/select.php on line 68.  

The db connect is good because I tested on a blank page, and I've not touched the page referenced by the error.  

I'm assuming that joomla already has a db connection established, so I could use that if I knew the variable.  In any case, what do I do to connect and run my queries for the select options?

Any help deeply appreciated!  If more info needed, just ask.

Question by:springthorpeSoftware
  • 4
  • 2
LVL 11

Expert Comment

by:Amanda Watson
ID: 33471229
I am not 100% clear what you are trying to achieve exactly.....

Your configuration.php file will contain the information to the database that is being used to run joomla which is in the root folder

Author Comment

ID: 33471469
Thank you so much for replying!

I have added fields to the jos_content table and I am trying to (1) validate what is entered for those fields when article is added/edited via the admin Article Manager and, if validation fails, display an alert and (2) trying to connect to another table in the same database to retrieve the option list for a "select" pull-down list for some other of those custom fields.

For (2), it's not that I don't know how to connect to the db or don't have the connection parameters, but that Joomla is throwing what is, from the surface, a totally unrelated error when I attempt to assign the db connection to a variable via PHP, e.g.
  [...assign values to connection variables...]
  $artDBC=mysql_connect($artHostname, $artUsername, $artPassword);
  $grpSQL = "SELECT DISTINCT grpGroup FROM artGroups ORDER BY grpGroup";
  $grpQry = mysql_query ($grpSQL,$artDBC);
The error shown by Joomla is in my original post and occurs when the mysql_connect function is called.

The page where I'm attempting the new database connection is  ../administrator/components/com_content/admin.content.html.php

Hope I'm making sense...  Let me know if you need further info.
Thanks again,

Author Comment

ID: 33471527
Attached screen shot may help explain error I'm seeing.
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

LVL 11

Expert Comment

by:Amanda Watson
ID: 33471595
So you have customised the Article Editing area to add more fields and have now got errors...
Or is there an extension you have used to do this?

You might want to tag this question to more experts in PHP.

Sorry I can't be more helpful

Author Comment

ID: 33475121
No, did not use an extension.  

Yes, the article editing has been customized, but everything works fine when the new fields are displayed as text boxes.  The problems came into play when (1) trying to validate the new fields and (2) trying to convert 3 of those text fields into <select> lists with options retrieved from a query.  

I'm not an expert with PHP, but do know my way around it, so I don't think it's a PHP issue.  More related to how Joomla! is constructed/operates.

Thanks for trying.  Can anyone else take a shot at it?

Accepted Solution

springthorpeSoftware earned 0 total points
ID: 33481671
OK, problem with db connection is now fixed.  I was trying to establish a second connection to the database when Joomla! already had one open.  By assuming that the connection was already there and using the default connection, I was able to query for the <options>.

Consider this one closed.  Will re-post the validation question if I still need to.


Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question