forms - Drupal - Set default value in hook_form_alter? -


I'm trying to upgrade some of the form fields, and I am using hook_form_alter (). I have tried many different ways, but in both cases, the fields are still empty. I am assuming that I should not set default_value and do not have the value, because if the user changes in the field, then I want to That they update correctly. Is it true?

I'm trying this:

  function mymodule_form_alter (& amp; $ form, and $ form_state, $ form_id) {if ($ form_id == 'user_profile_form' ) {If (arg (0) == 'user' and & amp; arg (1)) {$ user = user_load (arg (1)); $ Form ['profile_company_site'] = array ('# default_value' = & gt; $ user- & gt; profiles_company_site); $ Form ['profile_blog_url'] = array ('# default_value' = & gt; $ user- & gt; Profile_bug_rrl); $ Form ['profile_my_website_url'] = array ('# default_value' => = user- & gt; profiles_my_website_rrl); $ Form ['profile_first_name'] = array ('# default_value' = & gt; $ user- & gt; profiles_first_name); $ Form ['profile_last_name'] = array ('# default_value' = & gt; $ user- & gt; profile_last_name); }}  

I also tried to do this like this:

  function mymodule_form_alter (& amp; $ form, and $ form_state, $ form_id) {If ($ Form_id == 'user_profile_form') {if (arg (0) == 'user' and & arg (1)) {$ user = user_load (arg (1)); $ Form ['profile_company_site'] [# default_value '] = $ user- & gt; Profile_company_site]; $ Form ['profile_blog_url'] [# default_value '] = $ user- & gt; Profile_bug_ournal); $ Form ['profile_my_website_url'] ['# default_value'] = $ user- & gt; Profile_my_website_url); $ Form ['profile_first_name'] ['# default_value'] = $ user- & gt; Profile_for_name); $ Form ['profile_last_name'] ['# default_value'] = $ user- & gt; Profiles_lest_name); }}}}}  

You are missing an array level profile form field $ form Areas will not be at the top level, but depending on the name of the class, one will be in the sub-state. So if you've given your fields a category of 'example category', then your code should look like this:

prefix function mymodule_form_alter (and $ form, & $ form_state, $ form_id) {if ( $ Form_id == 'user_profile_form') {if (arg (0) == 'user' and & amp; arg (1)) {$ user = user_load (arg (1)); $ Form ['example category'] ['profile_company_site'] ['# default_value'] = $ user- & gt; Profile_company_site]; $ Form ['example category'] ['profile_blog_url'] ['# default_value'] = $ user- & gt; Profile_bug_ournal); $ Form ['example category'] ['profile_my_website_url'] ['# default_value'] = $ user- & gt; Profile_my_website_url); $ Form ['example category'] ['profile_first_name'] ['# default_value'] = $ user- & gt; Profile_for_name); $ Form ['example category'] ['profile_last_name'] ['# default_value'] = $ user- & gt; Profiles_lest_name); }}}

You should use the debugger (or at least one var_dump () ) to inspect that form array - which saves a lot of time is .


Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -