Forums

2 registration forms, one registered one special

pmsquillace 06 Jul, 2009
Hello All:

I am trying to write a php script that will edit register.php in joomla core so that if someone is using a certain form they register as registered, if not, then as author.

Before I get started writing this script and wasting time on this, does anyone think that this is NOT possible for any reason.

I have two forms and I need someone registered from one form as author and another as just registered.


Thanks for any thoughts or help on this.

Paul
GreyHead 07 Jul, 2009
Hi Paul,

This should be OK - I'd just recommend that you *don't* hack the core code but over-write the classes that you need modified. That will reduce any problems with future upgrades.

Bob
pmsquillace 07 Jul, 2009
Hi Bob,

Thanks for that bit of advice on what I want to do. When you say "

I'd just recommend that you *don't* hack the core code but over-write the classes that you need modified.



Are you talking about the joomla.php code or something in Chrono? I am a bit new to php so I was just going to write something like an

if URL http:
INSERT user->DB This
}else{
INSETT user-> DB That.

Not exact cause I am not thinking at the moment as to how to lay this out but was going to just put that in the forms Extra Code section or HTML section.

Thanks for any help on this you can give this newb at php....😀

Paul
GreyHead 07 Jul, 2009
Hi Paul,

Yes, I'm talking about the files in the Joomla (or ChronoForms) distributions - I saw "edit register.php" and a little warning flag went up.

Bob
pmsquillace 07 Jul, 2009
Thanks Bob.

I will prob. be back after I screw this script up. LOL...


Thanks for the advice on this,

Paul
pmsquillace 08 Jul, 2009
ok, I am back as promised.

In my form that is registering I did this:
<?
$url = JURI::current();
if( $url == 'index.php?option=com_chronocontact&chronoformname=provider_reg' ){

$var1 = 'author';

}else{

$var1 = 'registered';
}
?>


it did not work so I am wondering if I did this right.

Any thoughts or advice is all welcome...

thanks for the help

Paul
GreyHead 08 Jul, 2009
Hi Paul,

Please echo out the value of $url - from memory I think it will include the full url e.g. http://www.example.com/index.php . . .and so the == test will fail

Bob
nml375 08 Jul, 2009
Hi Paul & Bob,
As far as I can tell, JURI::current(); will not contain the query-part of the url, pretty much pointing to "http://www.yourdomain.tld/index.php". I'd suggest you use something like this instead:

<?php
$uri =& JURI::getInstance();
if ($uri->getVar('chronoformname') == 'provider_reg') {
  $var1 = 'author';
} else {
  $var1 = 'registered';
}
?>


/Fredrik

Edit: Missed the terminating ?> 😶
pmsquillace 08 Jul, 2009
Thanks so much Fred with help on this,

I did this here
<?php
$uri =& JURI::getInstance();
if ($uri->getVar('provider_reg') == 'provider_reg') {
  $var1 = 'author';
} else {
  $var1 = 'registered';
}
?>


Should I put the full URL in that first one because like this it did not work?

Thanks again for your help on this,

Paul
nml375 08 Jul, 2009
Hi Paul,
No, the first one should be literary 'chronoformname', as that is the variable we're pulling from the url, and then test it's value against 'provider_reg'.

/Fredrik
pmsquillace 08 Jul, 2009
LOL

I changed it thinking you put something in there to tell me like change this here. LOL

Thanks Fredrick I will try it now and let you know
pmsquillace 09 Jul, 2009
OK,

I don't know if this makes a difference but I put the script in just like you said but I am using an ACL to use my own group names.

Needless to say it did not work. They just go in as Registered.

Also, I have some other php code in there that I am using to check for usernames and such, does any of this matter?

Here is the complete php part before my form in the HTML Code tab


<?php
$db =& JFactory::getDBO();
$myurl =& JRequest:: geturi();

foreach ($_GET as $key => $val) {

   if ($key == 'username'){
      // username code
      $text =& JRequest:: getString('username');
      $sql = "
         SELECT COUNT(*)
            FROM jos_chronoforms_provider_reg
            WHERE username = ".$db->quote($text).";";
      $db->setQuery( $sql );
      echo "##@##";
      if ( $database->loadResult() != 0 ) {
        echo '<span class="red">Sorry, This Username is Already Taken</span>';
      } else {
        echo '<span class="green">Horray! This Username is Available</span>';
      }
      echo "##@##";
   }
   elseif ($key == 'email'){
      // email code
      $regemail =& JRequest:: getString('email');
      $sql = "
          SELECT COUNT(*)
              FROM jos_chronoforms_contractor_reg
              WHERE email = ".$db->quote($regemail).";";
      $db->setQuery( $sql );
      echo "##@##";
      if ( $database->loadResult() != 0 ) {
        echo '<span class="red">Sorry, This Email is Already Taken</span>';
      } else {
        echo '<span class="green">Horray! This email is Available</span>';
      }
      echo "##@##";
   }

}
?>

<?php
$uri =& JURI::getInstance();
if ($uri->getVar('chronoformname') == 'provider_reg') {
  $var1 = 'Providers';
} else {
  $var1 = 'Contractors';
}
?>



Thanks for any help or advice on this,

Paul
nml375 09 Jul, 2009
Hi Paul,
If that code is within the CF form, then it's pretty much pointless. The 'chronoformname' will always be the same, since you're always using the same form. I think both me and Bob thought you were editing some other module to affect it's behaviour depending on which CF form was displayed.
Also, I only see you setting the value of a custom variable named $var1 in your test, but don't use it for anything further on?

Are you actually using some additional CF-plugins such as "Joomla Registration" for a custom user registration form?

/Fredrik
pmsquillace 09 Jul, 2009
Oh,

I was putting it in the CF HTML Tab. I guess that will not cut it ehe?

Yes, I am using this with Joomla Registration to register someone on a certain form as something other than registered. (User using Contractor Form, would be registered in Joomla as Contractors).

Here is the link if this helps clear anything up. http://www.emrcontractor.com


Feel free to register or whatever to understand what I am trying to do.

Thanks so much for the help Fredrick and let me know what you think or if I am not thinking this the way I should.

Paul
nml375 09 Jul, 2009
'k
So, just to make sure I got everything right..
You have 2 CF forms which each uses the registration CF-plugin.
You also want some custom behaviour depending on which form was in use.

In this case, I'd recommend you "just" add the appropriate code to each form. That way, there's no need to check if we've loaded 'provider_reg' or 'contractor_reg', since 'provider_reg' would only contain the extra code for the provider registration.

Since you wish to alter the ACL group membership, I'd suggest you make use of the "extra after onsubmit" codebox in the registration plugin, as this should provide you access to the newly created user record. You'd have to do this for both forms, giving each their own piece of code.

/Fredrik
pmsquillace 10 Jul, 2009
Hi Fred

Yes that is right... I need to work on explaining myself better. LOL

You have 2 CF forms which each uses the registration CF-plugin. YED
You also want some custom behaviour depending on which form was in use.YES

Ok, I am going to try this now and will let you know how this works out.

Thanks for the help with this,

Paul
pmsquillace 10 Jul, 2009
ok, this is what I did.

I did what you said and added it to the joomla reg module but it was called "Extra after Registration code". Is this what you meant.

Then I added this code snip to that box
<?php
$uri =& JURI::getInstance();
if ($uri->getVar('chronoformname') == 'contractor_reg') {
  $var1 = 'Contractors';
}
?>


I basically took out the else part and left it as just an if...just do it. .LOL

let me know if i got this right because it did not go into the ACL group I made called contractors.

Thank you so much for all your help Fredrick, it is much appreciated..

Paul
nml375 10 Jul, 2009
Actually, you don't need any conditionals whatsoever..
Each form has it's own code.. what you enter for 'contractor_reg' won't affect 'provider_reg', nor the other way around...

The next step, would be to use whatever API is provided for your custom ACL (component, plugin or such?), and assign the newly created user record the proper group membership. Exactly how to do this is hard to tell without information on your custom access system, but a rough outline ( with CF 3.1 RC ) would look something like this:
<?
$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('', 'Author', 'ARO'));
if (!$user->save()) {
  JError::raiseWarning('', JText::_($user->getError()));
}
?>


/Fredrik
pmsquillace 10 Jul, 2009

Actually, you don't need any conditionals whatsoever..
Each form has it's own code.. what you enter for 'contractor_reg' won't affect 'provider_reg', nor the other way around...

The next step, would be to use whatever API is provided for your custom ACL (component, plugin or such?), and assign the newly created user record the proper group membership. Exactly how to do this is hard to tell without information on your custom access system, but a rough outline ( with CF 3.1 RC ) would look something like this:

<?
$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('', 'Author', 'ARO'));
if (!$user->save()) {
  JError::raiseWarning('', JText::_($user->getError()));
}
?>


/Fredrik



Thanks again Fredrik.... So basically do I open the zip file for my AEC and look for where in there I can mod it or am I just making sure it is all set up properly in the back end of joomla to show the groups I am looking for?

I have it set up in the back end already for contractors and providers so I am assuming you mean to open up the AEC files that are in the zipped component.


and if I am not using conditionals now how would this php look then, sorry, I am real new to php. I am thinking this..

<?php
$uri =& JURI::getInstance();
$uri->getVar('chronoformname') == 'contractor_reg') {
$var1 = 'Contractors';
}
?>
nml375 10 Jul, 2009
No, no, no...
You should use that (well, altered to suit your site's needs) code in the Registration CF-plugin's configuration box..
There is no need whatsoever to start editing files with cumbersome conditionals.
Each CF-Registration configuration is unique to the form you configured it with. Just as if you create two forms in CF, each form has it's own appearance, email setup, thank you page, and so on...

It's hard to provide any more detailed information without knowing what custom access control system you are using...

/Fredrik
pmsquillace 10 Jul, 2009
ok, I got that it goes in the registration plug in on submit box, I just did not know if the code I posted was going to do the trick with out the if in it.
<?php
$uri =& JURI::getInstance();
$uri->getVar('chronoformname') == 'contractor_reg') {
$var1 = 'Contractors';
}
?>


as far as acl I am using this one called Noix at this link, http://extensions.joomla.org/extensions/access-&-security/backend-&-full-access-control/7010/details

Not sure if you have any experience with that one or not.

Thanks so much for all this help,
nml375 10 Jul, 2009
No, that will most certainly not work, as you did not remove the If-conditional properly. If you were to remove that, the only thing you'd have left would be "$var1 = 'Contractors';"

The point is, you should really drop all of that code.. When we're working within ChronoForms, there is no point whatsoever to check the URL or such... Also, simply setting a variable ($var1) won't change how that user is registered. What is needed, is documentation (API) on which functions/methods to use from NoixACL to alter the registered user's group membership, or possibly the SQL-queries to mimic NoixACL.

I haven't used that package, but from what I've gathered, it makes use of the ACL support already present in Joomla, along with some custom tables to support multigroups.. Unfortunately, dev documentation seems rather limited from what I've found so far.

I did stumble across the plg_usernoixacl plugin, which adds hooks to the onBeforeStoreUser. This code then checks the 'multigroups' form field for a list of multigroup memberships. This means you might just get away with adding some JRequest::setVar() command in the "on submit before register" box with appropriate values, along with the previously posted code (edited accordingly).

I would have to investigate further regarding this though, and I'll see 'bout installing this on a dev-site in the next few days or so.

/Fredrik
pmsquillace 11 Jul, 2009
Thanks Fredrick,

Instead of you testing it on a dev site, would it be easier if I PM'd my site to you so you don't have to go through all that trouble?

Thanks for all the other info, I will see how far I get with the info you posted above...

Paul
nml375 15 Jul, 2009
Sorry for the delay, but I've had a few other things to attend to.
Anyway, I've managed to install the NoixACL package on a test-site without breaking too much.. would say this seems to have some potential.

Now, the first question that comes to mind; do you intend to use the Multigroup feature, or simply use the ability to add custom groups? If you don't care for multigroups, then the code I posted earlier should work without a hitch, just replace 'Author' with the name of the created group...

I am, however, having some issues getting the extra code to run at all on my test-site, although this might be an older version of CF...
/Fredrik
nml375 15 Jul, 2009
Followup:
Upgrading from CF3.1RC5 to CF3.1RC5.3 solved the issue of extra-code not being executed. Also successfully altered the group membership of the newly registered user using the previously posted code..

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