Solved

Two Joomla questions on custom fields

Posted on 2010-08-16
6
330 Views
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 http://forum.joomla.org/viewtopic.php?f=428&t=352285 (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.

Bruce
0
Comment
Question by:springthorpeSoftware
  • 4
  • 2
6 Comments
 
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
0
 

Author Comment

by:springthorpeSoftware
ID: 33471469
snowball77,
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,
Bruce
0
 

Author Comment

by:springthorpeSoftware
ID: 33471527
Attached screen shot may help explain error I'm seeing.
Bruce
Errors.png
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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
0
 

Author Comment

by:springthorpeSoftware
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?
Bruce
0
 

Accepted Solution

by:
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.

Thanks!!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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 (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
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.

758 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now