Forums

On Submit custom code not doing anything / Debug not showing

Moh-Aw 27 Jul, 2015
Hello,

I am trying to debug my form. I put a debugger on the very last position in the on submit event.

Apart from the debugger there is a custom code element with this code:

<?php
    $group_id_clanmembers = 11;
    $group_id_registered = 2;
    $user_id  = intval($form->data['player']);
    jimport( 'joomla.user.helper' );
    JUserHelper::addUserToGroup($user_id, $group_id_registered);
    JUserHelper::removeUserFromGroup($user_id, $group_id_clanmembers);
    $db =& JFactory::getDBO();
    $query = "update #__players set clan_id = null WHERE user_id = $user_id";
    $db->setQuery($query);
    $db->query();
?>


This code doesn't seem to get execute though, or it fails on the addUserToGroup method.

The debugging information after hitting the submit button is not shown. It just reloads the page. Do i have to enable something else?
GreyHead 27 Jul, 2015
Hi Moh-Aw,

Please try this version
<?php
$group_id_clanmembers = 11;
$group_id_registered  = 2;
$user_id  = intval($form->data['player']);
jimport( 'joomla.user.helper' );
\JUserHelper::addUserToGroup($user_id, $group_id_registered);
\JUserHelper::removeUserFromGroup($user_id, $group_id_clanmembers);
$db = \JFactory::getDBO();
$query = "
  UPDATE `#__players` 
    SET `clan_id` = null 
    WHERE `user_id` = $user_id;
";
$db->setQuery($query);
$db->execute();
?>
The main changes are to add the \J. . . as Max has put the ChronoForms code inside a separate namespace in CFv5 and to replace $db->query() with $db->execute - a Joomla! 3 change.

Bob
Moh-Aw 27 Jul, 2015
Thanks for the quick response. Unfortunately it's still not doing anything and the debug info isn't showing anything either.

I have a different form (which is the counterpart to the form above) which works perfectly with the following code:
<?php
$user =& JFactory::getUser();
$group_id_clanmembers = 11;
$group_id_registered = 2;
$user_id  = $user->id;
jimport( 'joomla.user.helper' );
JUserHelper::addUserToGroup($user_id, $group_id_clanmembers);
JUserHelper::removeUserFromGroup($user_id, $group_id_registered);
$authGroups = $user->getAuthorisedViewLevels(); 
$clan = $form->data['clan_id'];
$db =& JFactory::getDBO();
$query = "update `#__players`
                      set `clan_id` = $clan 
                 where `user_id` = $user_id";
$db->setQuery($query);
$db->execute();
?>
Moh-Aw 27 Jul, 2015
Oops sorry for the format above. Seems like there is no edit post function ?
GreyHead 27 Jul, 2015
Hi Moh-Aw,

I can only suggest that you debug your custom code.

+ Set site error reporting to Maximum temporarily and see if you get any PHP error messages.

+ Add echo statements to the code to output variables.

+ Comment out most of the code until you get some output, then remove the comments line by line until you find the point where the error is.

Bob
Moh-Aw 27 Jul, 2015
I have done what you wrote but it's not showing anything (no echo message from the code and no errors from the error reporting). After that I actually replaced everything in "onSubmit" with a "display message" module followed by a show stopper.

All it does is reload the page.
Moh-Aw 27 Jul, 2015
Answer
After looking at the source code in firefox i found that I have a form in a form. I'm calling the chronoform with the plugin in an article that already contains a form.
I'll try to find out how I solved this the last time.
Moh-Aw 27 Jul, 2015
Yes, that was the problem. I can close the other form prematurely before calling the chronoforms plugin.

Since I am not using the enclosing form anyway i will try to get rid of it. For now I have a stray
</form>
in my code. But at least it works.

Thanks for helping.
This topic is locked and no more replies can be posted.