Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Two Joomla questions on custom fields

Posted on 2010-08-16
Medium Priority
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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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.
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

Question has a verified solution.

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

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit ( and similar technologies have enjoyed wide adoption, making it possib…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

670 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