Hi,
I created a form to submit an article but I dunno how to send the category.
I used a "custom element PHP/HTML" as Element and I put it before the "Submit Article" to display all the categories. Here is the code:
but now I dunno how to submit the category and save the article with the selected category. Can please someone help me?
Thanks.
I created a form to submit an article but I dunno how to send the category.
I used a "custom element PHP/HTML" as Element and I put it before the "Submit Article" to display all the categories. Here is the code:
<?php
$db =& JFactory::getDBO();
$query = "
SELECT `id`, `title`, `alias`
FROM `#__categories`
WHERE `published` = 1 AND `access` = 1
ORDER BY `title`
";
$db->setQuery($query);
$categories = $db->loadObjectList();
$cat_options = array();
$cat_options[] = "<option value='' >Jobs</option>";
foreach ( $categories as $c ) {
$selected = '';
if ( $ws_id && $d->cat_id == $c->id ) {
$selected = "selected='selected'";
}
$cat_options[] = "<option value='{$c->id}' {$selected} >{$c->title}</option>";
}
?>
<div class="form_item">
<div class="form_element cf_select">
<label class="cf_label" style="width: 150px;">Category</label>
<select class="cf_select" title="" id="cat_id" name="cat_id" >
<?php echo implode("/n", $cat_options); ?>
</select>
</div>
<div class="cfclear"> </div>
</div>
but now I dunno how to submit the category and save the article with the selected category. Can please someone help me?
Thanks.
Hi mayhem ,
Unfortunately the Submit Article action doesn't support the Category as a variable :-( You can only set it as a fixed value from the action Configuration.
To do this you'd need to hand-code the article save.
Bob
Unfortunately the Submit Article action doesn't support the Category as a variable :-( You can only set it as a fixed value from the action Configuration.
To do this you'd need to hand-code the article save.
Bob
Hi Bob,
but I don't get it what you mean. In my array, the [cat_id] is set to 16 which it is a real id of a real category.
but I don't get it what you mean. In my array, the [cat_id] is set to 16 which it is a real id of a real category.
Data Array:
Array
(
[option] => com_chronoforms
[tmpl] => component
[chronoform] => Submit
[event] => submit
[Itemid] =>
[input_text_8] => myemail@email.com
[Title] => ee
[Author] => ee
[Full] => ee
[metadesc] => ee
[metakey] => ee
[featured] => 1
[cat_id] => 16
[input_submit_4] => Submit
[5b21fb99bb737bad508436a35fda52f8] => 1
)
Validation Errors:
Array
(
)
Hi mayhem,
Yes, but the Submit Article action doesn't pay any attention to that. It only uses the Category preset in the action configuration.
There is a case for a much better Submit Article action - maybe one day.
Bob
Yes, but the Submit Article action doesn't pay any attention to that. It only uses the Category preset in the action configuration.
There is a case for a much better Submit Article action - maybe one day.
Bob
Hi Bob,
so maybe I am not so confident with that and I don't understand if there is a way to do it.
Is it the simplest way to change directly the value in the DB or other way is possible?
Cheers.
so maybe I am not so confident with that and I don't understand if there is a way to do it.
Is it the simplest way to change directly the value in the DB or other way is possible?
Cheers.
Hi Mayhem,
It's possible to do it by running the Submit Article action then using a Custom Code action after that to update the category. If you add a debugger temporarily you'll see the new article id in the $form->data (probably as $form->data['cf_id'] and yo can use this to identify the record to update.
Bob
It's possible to do it by running the Submit Article action then using a Custom Code action after that to update the category. If you add a debugger temporarily you'll see the new article id in the $form->data (probably as $form->data['cf_id'] and yo can use this to identify the record to update.
Bob
Hi Bob,
I was thinking to update directly the DB because later I'll need to update an external DB.
This is my custom code before "submit event".
but an error appear when I'll submit. In detail:
Parse error: syntax error, unexpected T_VARIABLE in components/com_chronoforms/form_actions/custom_code/custom_code.php(19) : eval()'d code on line 13
Could you please help me?
Thanks.
I was thinking to update directly the DB because later I'll need to update an external DB.
This is my custom code before "submit event".
<?php
$hostname = 'host.com';
$username = 'user';
$password = 'password';
$dbname = 'dbname';
$categoryid = '17';
$itemid = '110';
$db = new PDO("mysql:host=$hostname;dbname=$database",$username,$password);
$update_stmt = $db->prepare('
UPDATE
#__content
SET
catid='$categoryid'
WHERE
id='$itemid'
');
$update_stmt->execute();
$update_stmt->close();
?>
but an error appear when I'll submit. In detail:
Parse error: syntax error, unexpected T_VARIABLE in components/com_chronoforms/form_actions/custom_code/custom_code.php(19) : eval()'d code on line 13
Could you please help me?
Thanks.
Hi mayhem,
Your quotes round/in the query string are wrong in a couple of ways. This may be better:
Bob
Your quotes round/in the query string are wrong in a couple of ways. This may be better:
$update_stmt = $db->prepare("
UPDATE
`#__content`
SET
`catid` = '{$categoryid}'
WHERE
`id` = '{$itemid}' ;
");
Bob
Hi Bob,
I replaced my old code with yours but the DB still doesn't affect the changes.
Indeed, the field 'catid' still be 17 in the 'id' 110.
Do you know why?
By the way, I had to delete the last statement
because an error appears saying "Fatal error: Call to undefined method PDOStatement::close()"
Thanks.
I replaced my old code with yours but the DB still doesn't affect the changes.
Indeed, the field 'catid' still be 17 in the 'id' 110.
Do you know why?
By the way, I had to delete the last statement
$update_stmt->close();
because an error appears saying "Fatal error: Call to undefined method PDOStatement::close()"
Thanks.
Hi mayhem,
I've no idea what the PDO code is - nothing that I recognise. I assumed that you had some reason for using that.
There are hundreds of examples of the Joomla! database code in the forums and FAQs.
Bob
I've no idea what the PDO code is - nothing that I recognise. I assumed that you had some reason for using that.
There are hundreds of examples of the Joomla! database code in the forums and FAQs.
Bob
Hi Bob,
just to be usefull for other users. The following is working solution:
just to be usefull for other users. The following is working solution:
<?php
//DB Connection
$Config = new JConfig();
//$option['driver'] = $Config->dbtype;
$option['host'] = $Config->host; // Database host name
$option['user'] = $Config->user; // User for database
$option['password'] = $Config->password; // Password for database
$option['dbname'] = $Config->db; // Database name
//$option['prefix'] = $Config->dbprefix; // Database prefix
$db = & JDatabase::getInstance($option);
$categoryid = '17';
$itemid = '110';
$db =& JFactory::getDBO();
$query = "UPDATE
`#__content`
SET
`catid` = '{$categoryid}'
WHERE
`id` = '{$itemid}' " ;
$db->setQuery($query);
$db->query();
?>
This topic is locked and no more replies can be posted.