Programatically Adding Additional Fields to Registration Page

Permalink
I'd like to add a short questionnaire to the registration page so that I can track what users signup when requesting access to various parts of the site.

Scenario:
User clicks 'Register' from the home page. -> Show them the standard registration form (name, email, password)

Scenario 2:
User clicks on a link on a secondary page advertising Acme. -> Show the standard fields plus a few questions like 'Do you intend to use this anvil to crush a roadrunner?'

One confounding issue is that we'd like to set this up so that there could be different questions based on what link they clicked on; we'd like to track it.

Any help is appreciated.

SkyBlueSofa
 
jordanlev replied on at Permalink Reply
jordanlev
You'll need to create your own custom registration page for scenario 2. Just make a new single_page, and check out the code I have for an ajax login/reg page here:http://www.concrete5.org/community/forums/themes/customizing-login-...

Should be easy to take out the ajax/javascript stuff if you want it to post normally. Note that there are examples in there of how to output fields for custom attributes -- which is what you'll want to use for your additional questions.

You'll need to code up the proper login on the single_page to show/hide the appropriate questions based on other answers they've provided (and hence this means you should *not* make any of your custom attributes required, because in some scenarios the user won't be entering anything for them -- instead use javascript to validate and hope that's good enough).

Good luck!
shwaydogg replied on at Permalink Reply
shwaydogg
@SkyBlueSofa, what did you end up doing? Do you have a live example?

@jordanlev, I am not completely following what is going on in your 'ajax login/reg page'.

1. What is the goal? I did not really get bastien31's question. If the goal is to just have the login and register on the same page that can be accomplished with out any fancy ajax as shown here:http://www.concrete5.org/documentation/how-tos/designers/creating-a... and then some additional styling and simple js to hide and show each form for the accordion look and feel.

EDIT: A partial answer to my question I have since realized is that error messages are handled on the same page and the user is redirected to a specific page. This keeps the default login and register.php from ever being encountered by the user. Is there more than this?

2. I tested your code by creating a 'single page' for it. Both the login and register forms show up but there is no register button for the register form. And there are no hidden attributes to be seen.

EDIT: My oversight was I had not added the custom user attributes 'zip_code' and 'full_name' in c5. Everything is working on the front end now.


3. What my real concern is how you added 'custom user attributes'. Like @SkyBlueSofa, I would like to have more control over the form and have it end up in the user details in c5.

I used the following from your example code to add a 'custom user attribute' to the front end form but the input did not make it into the 'user attributes' on backend. Any ideas why?

<?php Loader::model('attribute/categories/user'); ?>
...
name="akID[<?php echo UserAttributeKey::getByHandle('zip_code')->getAttributeKeyID(); ?>][value]"
SkyBlueSofa replied on at Permalink Reply
SkyBlueSofa
I wound up creating a new block called 'required form' that checks to see if a visitor has filled out a form. If they have, let them access the page. If not, show them the form (with their information like name, email, etc. autofilled).

I haven't released the code for 'required form' because of changes necessary to the core form functionality.
jordanlev replied on at Permalink Reply
jordanlev
@shwaydogg, what's going on in my 'ajax login/reg page' is showing how to les users log in or register for your site without redirecting them to a separate login page (for example, many sites have a design where login is handled via a drop-down menu in the top-right corner).

It also serves (I think) as a good example of what the absolute minimum requirements are for customizing your own login/reg form. As opposed to the built-in login/reg page, which has a *ton* of options on it -- things like password resets, OpenID integration, etc. -- which I personally don't always need on my own custom designs.

-Jordan