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
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.
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Part of the Global Positioning System A geocode ( is the major subset of a GPS coordinate (, the other parts being the altitude and t…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

751 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