Call an Article from a Field Name

hopemanjohn 29 Jan, 2013
Is there anyway to call an article by name or by ID from a ChromoForm Field?

For example:

If I have an article with a name say 88888 which has an ID of say 73 and I have a ChronoForm which has a Field Name of say (code) how can I get:

1. The article to be displayed when the correct code is entered in the ChronoForm Field Named Say (code).

2. If the code entered is wrong then a customized error message will be shown.
GreyHead 30 Jan, 2013
Hi hopemanjohn,

I'm not quite sure how all this comes together but here's a suggestion.

You can use a Custom Code action (or my Event Switcher [GH] action) in the On Submit event of your form. Use a little DB query to check if there is an article with that title, if there is then redirect the user to it; if not then show an error message.

You could use a DB Record Loader action instead of coding by hand but you still have to code the check so probably easier to do both at once:
<?php
$db =& JFactory::getDBO();
$query = "
    SELECT `id`
        FROM `#__contents`
        WHERE `title` = '{$form->data['code']}' ;
";
$db->setQuery($query);
$art_id = $db->loadResult();
$message = '';
if ( $art_id ) {
  $url = 'index.php?option=com_content&view=article&id='.$art_id;
} else {
  $url = 'add form url here;
  $message = 'Some message';
}
$mainframe->redirect($url, $message);
?>


Bob
This topic is locked and no more replies can be posted.