" />   Name name; ?>" />   Group gid == "18" ? 'selected' : '' ?> >Registeredgid == "37" ? 'selected' : '' ?> >TrialMembergid == "36" ? 'selected' : '' ?> >ClanMembergid == "46" ? 'selected' : '' ?> >Retired    THANKS!"> Trying to use ChronoForms to change user group, display name - Forums

Forums

Trying to use ChronoForms to change user group, display name

tshooter91 25 Mar, 2010
Hello all,

I am trying out ChronoForms for a new website for a gaming clan. We have certain users that manage clan membership and I want them to have a form on the frontend where they can change a registered user's group and name.

I have the form created, it is populated with the registered user's username, name, and current group (in a dropdown). When I change the name and group and hit submit, my changes are not written to the database.

I have enabled Data Storage, picked jos_users and Saving Data is set to "After Email" even though I am not doing anything with email. Debug on shows me no errors. I assumed the names of the form text fields and pulldown needed to match the field names in jos_users.

What else do I need to do? I've looked through the tutorials and the forums and can't find anything about getting data from a form into a joomla core table. If something is already written up, please point me to it.

Here is my Form HTML:

<? $user = &JFactory::getUser(JRequest::getVar('uid')); ?>
<div class="form_item">
<div class="form_element cf_textbox">
<label class="cf_label" style="width: 150px;">UserName</label>
<input class="cf_inputbox" maxlength="150" size="30" title="" id="text_0" name="username" type="text" value="<?= $user->username; ?>" />

</div>
<div class="cfclear"> </div>
</div>

<div class="form_item">
<div class="form_element cf_textbox">
<label class="cf_label" style="width: 150px;">Name</label>
<input class="cf_inputbox" maxlength="150" size="30" title="" id="text_1" name="name" type="text" value="<?= $user->name; ?>" />

</div>
<div class="cfclear"> </div>
</div>

<div class="form_item">
<div class="form_element cf_dropdown">
<label class="cf_label" style="width: 150px;">Group</label>
<select class="cf_inputbox" id="select_2" size="1" title="" name="gid">

<option value="18" <?= $user->gid == "18" ? 'selected' : '' ?> >Registered</option>
<option value="37" <?= $user->gid == "37" ? 'selected' : '' ?> >TrialMember</option>
<option value="36" <?= $user->gid == "36" ? 'selected' : '' ?> >ClanMember</option>
<option value="46" <?= $user->gid == "46" ? 'selected' : '' ?> >Retired</option>
</select>

<? //echo var_dump($user); ?>


</div>
<div class="cfclear"> </div>
</div>

<div class="form_item">
<div class="form_element cf_button">
<input value="Submit" name="button_3" type="submit" />
</div>
<div class="cfclear"> </div>
</div>

THANKS!
GreyHead 25 Mar, 2010
Hi tshooter91,

I think you need the user id in a hidden input with name='id' otherwise there is no index to match.

There may be other problems too - turn site debug on to see the MySQL query that is being generated so that you can debug it.

Writing directly to jos_users is not the Joomla recommended way to update a Joomla User record. It's better to update the User Object and then use the $user->save() method on it. Fredrik (nml375) has posted about this here a few times.

Bob
tshooter91 26 Mar, 2010
You were right about adding a hidden input for the ID field. It now saves the data in my form.

My problem now is that I have to change the GID and the USERTYPE fields in jos_users for it to be correct.

I understand your recommendation to use a JUser object instead. I'm assuming I'd have to use the Onsubmit field to do the actual setting and saving of the object properties then, right? Do I have to set up html form post and request variables to pass my form selections on to the onsubmit code?

Thanks again.
GreyHead 26 Mar, 2010
Hi tshooter91,

Someone posted the code to change the usertype in a post about the Registration Plugin a few weeks ago.

You don't need to do anything special to pass the information, you can access the post and get variables using JRequest::get

Bob
nml375 26 Mar, 2010
Hi,
Some time ago, I used the following "on extra - after" code with the Registration plugin in order to grant registrants "Testgrupp" privileges (an extra group I added using NoIX ACL). It shouldn't be too hard to adapt this code to edit an already existing user account.
<?
$user =& $MyPlugins->cf_joomla_registration['user'];
$auth =& JFactory::getACL();

// Grant user "Author" membership using Joomla's JAuthorization class
$user->set('gid', $auth->get_group_id('', 'Testgrupp', 'ARO'));
if (!$user->save()) {
  JError::raiseWarning('', JText::_($user->getError()));
}

?>


You'd have to replace the $user =& $MyPlugins... with $user =& JFactory::getUser($uid); or such, and adjust the 'Testgrupp' string to the name the user should be changed to.
Finally calling the $user->save() method will take care of udating any and all needed records in the ARO and ACO tables..

Let me know if you need further help adopting the code for your needs.

/Fredrik
tshooter91 29 Mar, 2010
Guys,

Thanks for all your help so far. I know have a working form and it emails the user with a welcome email depending on the new group. The last piece I need is a way to prevent normal users from accessing the form. Even when I'm not logged in to the site, I can use the URL to change somebody's user group!

So I've searched the forums on restricting access or securing the form and all I've found relates to SSL. How can I restrict the form to access from only one group? I have groups created in noixACL, so the group ID is 43 and it's out of the normal Joomla groups.

I'm cleaning up my code and will be posting what I did once I have this last piece.

Thanks!
GreyHead 29 Mar, 2010
Hi tshooter91,

Try this in the beginning of the Form HTML box
<?php
if ( !$mainframe->isSite() ) { return; }
$user = & JFactory::getUser();
if ( !in_array($user->gid, array('24', '25') ) {
  $mainframe->redirect('index.php');
}
?>
. . . 

Bob
This topic is locked and no more replies can be posted.