Using Sourcerer plugin to insert into table

General questions relating to Joomla! 4.x.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting.
Forum Post Assistant - If you are serious about wanting help, you should use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10
Post Reply
ilanocf
Joomla! Apprentice
Joomla! Apprentice
Posts: 11
Joined: Mon May 08, 2017 12:50 pm

Using Sourcerer plugin to insert into table

Post by ilanocf » Mon May 20, 2024 4:38 pm

Hello everybody!

I created a table for the user to evaluate the company's services for whom I am developing the website and I need to place a form in Joomla to make insertions in this table. For this I need to use Soucerer but I need help. Download the code below. Just one detail, I'm using the free version.

{source}

<div class="row">
<div class="col-sm-4">&nbsp;</div>
<div class="col-sm-8">
<div class="h3">Avalie-nos</div>
<div>&nbsp;</div>
<form action="/index.php" method="post">
<div><input name="option" type="hidden" value="com_content" /></div>
<div><input name="task" type="hidden" value="saveAvaliacao" /></div>
<div><input name="article_id" type="hidden" value="{ARTICLE_ID}" /></div>
<div><label for="email">E-mail:</label></div>
<div><input name="email" required="" type="email" id="email" /></div>
<div><label for="estrela">Estrela:</label></div>
<div><span class="star-rating star-5"> <input name="rating" required="" type="radio" value="1" /><i></i> <input name="rating" type="radio" value="2" /><i></i> <input name="rating" type="radio" value="3" /><i></i> <input name="rating" type="radio" value="4" /><i></i> <input name="rating" type="radio" value="5" /><i></i> </span></div>
<div><label for="observacao">Comentário:</label></div>
<div><textarea cols="50" name="comentario" rows="4" id="comentario" class="form-control"></textarea><br /> <input type="submit" value="Enviar" class="btn btn-primary btn-sm" /></div>
</form></div>
</div>

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['email']) && isset($_POST['rating']) && isset($_POST['comentario'])) {
$db = JFactory::getDbo();

$query = $db->getQuery(true)
->insert($db->quoteName('josoy_pilotis_avaliacao'))
->columns(array('avaliadata', 'email', 'rating', 'comentario'))
->values($db->quote(date('Y-m-d H:i:s')) . ', ' . $db->quote($_POST['email']) . ', ' . $db->quote($_POST['rating']) . ', ' . $db->quote($_POST['comentario']));

$db->setQuery($query);
$result = $db->execute();

if ($result) {
echo 'Avaliação inserida com sucesso!';
} else {
echo 'Ocorreu um erro ao inserir a avaliação.';
}
}
?>{/source}

When executed, the message is returned:
View class not found [name, type, prefix]: page, html, site

Thanks
Last edited by toivo on Tue May 21, 2024 8:38 am, edited 1 time in total.
Reason: mod note: typo in subject

ilanocf
Joomla! Apprentice
Joomla! Apprentice
Posts: 11
Joined: Mon May 08, 2017 12:50 pm

Re: Using Soucerer plugin to insert into table

Post by ilanocf » Mon May 20, 2024 4:52 pm

Enabling Joomla 4's Debug mode returns the following:

Function: ()
Location: JROOT/libraries/src/MVC/Controller/BaseController.php:837

Function: Joomla\CMS\MVC\Controller\BaseController->getView()
Location: JROOT/libraries/src/MVC/Controller/BaseController.php:615

Function: Joomla\CMS\MVC\Controller\BaseController->display()
Location: JROOT/components/com_content/src/Controller/DisplayController.php:121

Function: Joomla\Component\Content\Site\Controller\DisplayController->display()
Location: JROOT/libraries/src/MVC/Controller/BaseController.php:693

Function: Joomla\CMS\MVC\Controller\BaseController->execute()
Location: JROOT/libraries/src/Dispatcher/ComponentDispatcher.php:143

Function: Joomla\CMS\Dispatcher\ComponentDispatcher->dispatch()
Location: JROOT/components/com_content/src/Dispatcher/Dispatcher.php:56

Function: Joomla\Component\Content\Site\Dispatcher\Dispatcher->dispatch()
Location: JROOT/libraries/src/Component/ComponentHelper.php:361

Function: Joomla\CMS\Component\ComponentHelper::renderComponent()
Location: JROOT/libraries/src/Application/SiteApplication.php:208

Function: Joomla\CMS\Application\SiteApplication->dispatch()
Location: JROOT/libraries/src/Application/SiteApplication.php:249

Function: Joomla\CMS\Application\SiteApplication->doExecute()
Location: JROOT/libraries/src/Application/CMSApplication.php:293

Function: Joomla\CMS\Application\CMSApplication->execute()
Location: JROOT/includes/app.php:61

Function: require_once()
Location: JROOT/index.php:32

SharkyKZ
Joomla! Hero
Joomla! Hero
Posts: 2965
Joined: Fri Jul 05, 2013 10:35 am
Location: Parts Unknown

Re: Using Soucerer plugin to insert into table

Post by SharkyKZ » Tue May 21, 2024 6:50 am

You should reconsider this. Using Sourcerer is fundamentally wrong. It's also volatile, unmaintainable and insecure. Read some documentation how to write a proper Joomla extension.

ilanocf
Joomla! Apprentice
Joomla! Apprentice
Posts: 11
Joined: Mon May 08, 2017 12:50 pm

Re: Using Sourcerer plugin to insert into table

Post by ilanocf » Tue May 21, 2024 4:34 pm

What would you recommend me? Can I do something like this using the Custom HTML module?
I need to integrate new features into Joomla 4 so that it is more than a content manager.

gws
Joomla! Champion
Joomla! Champion
Posts: 6046
Joined: Tue Aug 23, 2005 1:56 pm
Location: South coast, UK
Contact:

Re: Using Sourcerer plugin to insert into table

Post by gws » Tue May 21, 2024 5:00 pm

Most of the form builders will do what you need in your first post.


Post Reply

Return to “General Questions/New to Joomla! 4.x”