input;
$db = Factory::getContainer()->get('DatabaseDriver');
// ===== CONFIGURATION =====
$allowedCategoryParentId = 8; // Parent category ID
$allowedTagParentId = 1; // Parent tag ID for language dropdown
$notificationDelay = 4000; // milliseconds
$successMsg = '';
$errorMsg = '';
// Handle POST submission
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// CAPTCHA validation
$captchaPlugin = $app->get('captcha', '0');
if ($captchaPlugin !== '0') {
$captcha = Captcha::getInstance($captchaPlugin, ['namespace' => 'com_frontsubmit']);
try {
$captcha->checkAnswer($input->get('g-recaptcha-response'));
} catch (Exception $e) {
$errorMsg = Text::_('Invalid CAPTCHA, please try again.');
}
}
if (!$errorMsg) {
$title = $input->getString('title');
$content = $input->getString('content');
$categoryId = (int) $input->get('catid');
$languageTag = $input->getString('language');
// Remove links, scripts, iframes, phone numbers
$patterns = [
'/]*>(.*?)/is', // links
'/https?:\/\/[^\s"]+/i', // plain URLs
'/]*>.*?/is',
'/]*>.*?/is',
'/\+?\d[\d\s\-()]{6,15}/' // phone numbers
];
$replacement = '[removed by the administrator]';
$title = strip_tags($title);
$title = preg_replace($patterns, $replacement, $title);
$content = preg_replace($patterns, $replacement, $content);
// Create article
$table = Table::getInstance('Content', 'JTable', []);
$data = [
'title' => $title,
'alias' => '',
'introtext' => $content,
'fulltext' => '',
'catid' => $categoryId,
'state' => 0,
'created' => date('Y-m-d H:i:s'),
'created_by' => $user->id,
'language' => $languageTag,
];
if ($table->bind($data) && $table->check() && $table->store()) {
$successMsg = Text::_('✅ Your article has been submitted successfully and is awaiting administrator approval.');
} else {
$errorMsg = Text::_('Error saving article. Please try again.');
}
}
}
// Fetch allowed categories (parent + subcategories)
$query = $db->getQuery(true)
->select(['id','title'])
->from('#__categories')
->where('extension = '.$db->quote('com_content'))
->where('published = 1')
->where('(id = '.(int)$allowedCategoryParentId.' OR parent_id = '.(int)$allowedCategoryParentId.')')
->order('title ASC');
$db->setQuery($query);
$categories = $db->loadObjectList();
// Fetch language options from tags under specific parent tag
$query = $db->getQuery(true)
->select(['id','title'])
->from('#__tags')
->where('parent_id = '.(int)$allowedTagParentId)
->where('published = 1')
->order('title ASC');
$db->setQuery($query);
$languages = $db->loadObjectList();
?>
-- Select Category --
title); ?>
-- Select Language --
title); ?>
get('captcha', '0');
if ($captchaPlugin !== '0') {
$captcha = Captcha::getInstance($captchaPlugin, ['namespace'=>'com_frontsubmit']);
echo $captcha->display('captcha', 'captcha', 'required');
}
?>
setTimeout(() => {
const alertEl = document.getElementById('successAlert');
if (alertEl) alertEl.classList.remove('show');
}, );