Additional user account field

View: New views
6 Messages — Rating Filter:   Alert me  

Additional user account field

by Dayton Perkins :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.

I am doing a networking site for some one that is targeting college students. It is important that they have a campus associated with their account. I need a little advice as to how best to approach this.

I have a database table of campuses that includes a state field. My first take was to add some JavaScript in the registration form. Users select a state from a select list, which uses AJAX to populate a div with a list of links for that state. Choosing a link then in turn gives a visual indication that a campus has been chosen and populates a hidden input value which was empty, etc. etc. This was not too tough using jQuery and what have you.

I used something like this:

function campus_validate($form, &$form_state){

      if($form_state['values']['campus']==""){

            drupal_set_message(t('Please select a state and campus'));

            return false;

      }

      return true;

}

 

function user_form_alter(&$form, $form_state, $form_id) {

      if ($form_id == 'user_register') {

            $form['Personal']['campus'] = array(

              '#type' => 'hidden',

              '#default_value' => "",

              '#required' => TRUE        

);

// the following are not correct, but the idea is I need to validate the extra fields I am adding. I can muddle through these.

            $form['Personal']['campus']['#element_validate'] = array('campus_validate');

            // $form['profile_sex']['#element_validate'] = array('sex_validate');

      }

}

So I think you can see where I am going with this although it isn’t complete.

The next thing I want to do, is I prefer to add a tab for editing the users’ campus. I prefer this to adding to the user/edit form. Once again, I will need to have a state select that will use AJAX to query and provide a list. Fortunately, I can probably reuse a lot of the code from the registration form. Can someone please suggest how to add a tab to /user, and if you have any suggestions as to making this less labor-intensive, that would be super! J

If the whole thing should be tossed, and go with multi-step submissions, please point me the right way on that.

Thank you so much.

 

 

Kindest Regards,

Dayton Perkins

Good News Design

Interactive  Web sites for business

dayton@...

http://goodnewsdesign.com

Phone:  616-399-5617

Cell: 616-405-6360

3611 Butternut Drive Lot 40

Holland MI 49424

 

 


Re: Additional user account field

by Earnie :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Quoting Dayton Perkins <perkinsd@...>:

>
> If the whole thing should be tossed, and go with multi-step submissions,
> please point me the right way on that.
>

Sounds like you're on the correct track. You want to study the following:

http://api.drupal.org/api/group/form_api
http://api.drupal.org/api/drupal/developer--topics--forms_api_reference.html/6#autocomplete_path
http://api.drupal.org/api/drupal/developer--topics--forms_api_reference.html/6#ahah
http://drupal.org/project/ahah_helper

--
Earnie
-- http://r-feed.com/           -- http://for-my-kids.com/
-- http://www.4offer.biz/       -- http://give-me-an-offer.com/



Re: [work] Re: Additional user account field

by Dayton Perkins :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks, Earnie. Although pretty new to it, I am dedicated to Drupal. I
actually already wrote JavaScript as I felt a list would be better than
using autocomplete.
Can you clue me quickly as to adding the tab to /user? I have no problem
creating the form as I have done this a few times.

Kindest Regards,
Dayton Perkins
Good News Design
Interactive  Web sites for business
mailto:dayton@...
http://goodnewsdesign.com
Phone:  616-399-5617
Cell: 616-405-6360
3611 Butternut Drive Lot 40
Holland MI 49424
 
 
-----Original Message-----
From: development-bounces@... [mailto:development-bounces@...]
On Behalf Of Earnie Boyd
Sent: Thursday, September 24, 2009 8:14 AM
To: development@...
Subject: [work] Re: [development] Additional user account field

Quoting Dayton Perkins <perkinsd@...>:

>
> If the whole thing should be tossed, and go with multi-step submissions,
> please point me the right way on that.
>

Sounds like you're on the correct track. You want to study the following:

http://api.drupal.org/api/group/form_api
http://api.drupal.org/api/drupal/developer--topics--forms_api_reference.html
/6#autocomplete_path
http://api.drupal.org/api/drupal/developer--topics--forms_api_reference.html
/6#ahah
http://drupal.org/project/ahah_helper

--
Earnie
-- http://r-feed.com/           -- http://for-my-kids.com/
-- http://www.4offer.biz/       -- http://give-me-an-offer.com/



Re: Additional user account field

by Scott Reynen :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Sep 24, 2009, at 5:28 AM, Dayton Perkins wrote:

> If the whole thing should be tossed, and go with multi-step  
> submissions, please point me the right way on that.

That's certainly a more accessible option.  Your current method simply  
won't work at all for anyone browsing without JavaScript enabled.  
While that's usually a small minority, it will be incredibly annoying  
for them to get validation failures on form elements they can't  
possibly change.  How many campuses are in your list?  You may be able  
to make it both accessible and a more responsive UX by loading the  
entire list in the form with markup (e.g. class) references to the  
relevant states, and then hiding the irrelevant options with JS as a  
state is selected.  If that's too many campuses to load up front, I'd  
go with a multi-step form.

--
Scott Reynen
MakeDataMakeSense.com



Re: [work] Re: Additional user account field

by Dayton Perkins :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Scott there are approximately 2000

Kindest Regards,
Dayton Perkins
Good News Design
Interactive  Web sites for business
mailto:dayton@...
http://goodnewsdesign.com
Phone:  616-399-5617
Cell: 616-405-6360
3611 Butternut Drive Lot 40
Holland MI 49424
 
 

-----Original Message-----
From: development-bounces@... [mailto:development-bounces@...]
On Behalf Of Scott Reynen
Sent: Thursday, September 24, 2009 9:09 AM
To: development@...
Subject: [work] Re: [development] Additional user account field

On Sep 24, 2009, at 5:28 AM, Dayton Perkins wrote:

> If the whole thing should be tossed, and go with multi-step  
> submissions, please point me the right way on that.

That's certainly a more accessible option.  Your current method simply  
won't work at all for anyone browsing without JavaScript enabled.  
While that's usually a small minority, it will be incredibly annoying  
for them to get validation failures on form elements they can't  
possibly change.  How many campuses are in your list?  You may be able  
to make it both accessible and a more responsive UX by loading the  
entire list in the form with markup (e.g. class) references to the  
relevant states, and then hiding the irrelevant options with JS as a  
state is selected.  If that's too many campuses to load up front, I'd  
go with a multi-step form.

--
Scott Reynen
MakeDataMakeSense.com



Re: [work] Re: Additional user account field

by Earnie :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Quoting Dayton Perkins <perkinsd@...>:

> Thanks, Earnie. Although pretty new to it, I am dedicated to Drupal. I
> actually already wrote JavaScript as I felt a list would be better than
> using autocomplete.
> Can you clue me quickly as to adding the tab to /user? I have no problem
> creating the form as I have done this a few times.
>

Search for MENU_LOCAL_TASK.  You use hook_menu to return an item you  
want to add to the path with a MENU_LOCAL_TASK and it becomes  
available as a tab on the main page.  You may have to use  
hook_menu_alter to make the original menu entry a  
MENU_DEFAULT_LOCAL_TASK.

--
Earnie
-- http://r-feed.com/           -- http://for-my-kids.com/
-- http://www.4offer.biz/       -- http://give-me-an-offer.com/