I pretty much followed this and the answer there really helped me a lot so far. Currently I'm stuck with either a 500 (Internal Server Error)
or a 400 (Bad Request)
Error.
My craft/storage/runtime/logs/craft.log
read the following:
For 400
[error] [exception.Craft\HttpException.400] Craft\HttpException: POST param “title” doesn’t exist. in XXX/craft/app/services/HttpRequestService.php:509
Stack trace:
0 XXX/craft/app/controllers/TagsController.php(235): Craft\HttpRequestService->getRequiredPost('title')
1 XXX/craft/app/framework/web/actions/CInlineAction.php(49): Craft\TagsController->actionCreateTag()
2 XXX/craft/app/framework/web/CController.php(308): CInlineAction->runWithParams(Array)
3 XXX/craft/app/framework/web/CController.php(286): CController->runAction(Object(CInlineAction))
4 XXX/craft/app/framework/web/CController.php(265): CController->runActionWithFilters(Object(CInlineAction), Array)
5 XXX/craft/app/framework/web/CWebApplication.php(282): CController->run('createTag')
6 XXX/craft/app/etc/web/WebApp.php(818): CWebApplication->runController('tags/createTag')
7 XXX/craft/app/etc/web/WebApp.php(288): Craft\WebApp->_processActionRequest()
8 XXXcraft/app/framework/base/CApplication.php(185): Craft\WebApp->processRequest()
9 XXX/craft/app/index.php(62): CApplication->run()
10 XXX/index.php(19): require_once('/var/www/vhosts...')
11 {main}
REQUEST_URI=/actions/tags/createTag
HTTP_REFERER=XXX
---
When I add title: "Tags"
to the POST data
it results in the 500
with following error:
[error] [system.db.CDbCommand] CDbCommand::execute() failed: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`craft_`.`craft_tags`, CONSTRAINT `craft_tags_groupId_fk` FOREIGN KEY (`groupId`) REFERENCES `craft_taggroups` (`id`) ON DELETE CASCADE). The SQL statement executed was: INSERT INTO `craft_tags` (`uid`, `groupId`, `id`, `dateUpdated`, `dateCreated`) VALUES (:yp0, :yp1, :yp2, :yp3, :yp4).
2016/11/03 22:16:01 [error] [exception.CDbException] CDbException: CDbCommand failed to execute the SQL statement: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`craft_`.`craft_tags`, CONSTRAINT `craft_tags_groupId_fk` FOREIGN KEY (`groupId`) REFERENCES `craft_taggroups` (`id`) ON DELETE CASCADE) in XXX/craft/app/framework/db/CDbCommand.php:358
Stack trace:
#0 XXX/craft/app/framework/db/ar/CActiveRecord.php(1081): CDbCommand->execute()
#1 XXX/craft/app/framework/db/ar/CActiveRecord.php(810): CActiveRecord->insert(NULL)
#2 XXX/craft/app/services/TagsService.php(396): CActiveRecord->save(false)
#3 XXX/craft/app/controllers/TagsController.php(237): Craft\TagsService->saveTag(Object(Craft\TagModel))
#4 XXX/craft/app/framework/web/actions/CInlineAction.php(49): Craft\TagsController->actionCreateTag()
#5 XXX/craft/app/framework/web/CController.php(308): CInlineAction->runWithParams(Array)
#6 XXX/craft/app/framework/web/CController.php(286): CController->runAction(Object(CInlineAction))
#7 XXX/craft/app/framework/web/CController.php(265): CController->runActionWithFilters(Object(CInlineAction), Array)
#8 XXX/craft/app/framework/web/CWebApplication.php(282): CController->run('createTag')
#9 XXX/craft/app/etc/web/WebApp.php(818): CWebApplication->runController('tags/createTag')
#10 XXX/craft/app/etc/web/WebApp.php(288): Craft\WebApp->_processActionRequest()
#11 XXX/craft/app/framework/base/CApplication.php(185): Craft\WebApp->processRequest()
#12 XXX/craft/app/index.php(62): CApplication->run()
#13 XXX/index.php(19): require_once('/var/www/vhosts...')
#14 {main}
REQUEST_URI=/actions/tags/createTag
HTTP_REFERER=XXX
---
Any suggestions would be much appreciated. This is the JS code I'm using:
$('#new-tag').click(function() {
var name = prompt('What’s the new tag name?');
if (!name) return;
var data = {
title: 'tags',
groupId: 2,
name: name
};
$.post('/actions/tags/createTag', data, function(response) {
if (response.success) {
$('<label>' +
'<input type="checkbox" name="fields[tags][]" value="'+response.id+'" checked="checked"/> ' +
name +
'</label>').appendTo($('#tags'));
}
else {
alert('Unable to create that tag.');
}
});
});