Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Whenever I change the country it removes all the hook_form_alter changes and conditions. Even I have set my own submit callback which is removed when I change the country.
I am using profile2 module and creating form using following custom code.
//load user personal contact profile form
global $user;
$profile2 = profile2_by_uid_load($user->uid, 'personal_contact_info');
$entity_form = entity_ui_get_form('profile2', $profile2, 'edit');
drupal_set_title(t('Personal and contact info'));
//render drupal form
return drupal_render($entity_form);
Now when ever I make country change request using ajax remove my following alter set:
unset($form['actions']['submit']);
unset($form['actions']['delete']);
$form['field_company_search'] = array(
'#title' => htmlspecialchars_decode($title) . '<span title="This field is required." class="form-required">*</span>',
'#type' => 'textfield',
'#maxlength' => 60,
'#autocomplete_path' => 'org/autocomplete',
'#description' => check_plain($description)
);
Please help?
Comments
Comment #2
Jaypan CreditAttribution: Jaypan at Jaypan commentedComment #3
Jaypan CreditAttribution: Jaypan at Jaypan commentedComment #4
Jaypan CreditAttribution: Jaypan at Jaypan commentedYou need to show what functions that code is in. The function name/hook name provides context, without it, we have no idea how this code is going to affect anything.
Comment #5
chera.jaswinder CreditAttribution: chera.jaswinder commentedFollowing is the function in address field module due to which when request is made from address plugin it causes to change in the form as describe above. If you need any further information please let me know.
Comment #6
Jaypan CreditAttribution: Jaypan at Jaypan commentedYou showed us different code in this new post. You need to show the code from the original post, but show what functions it is in.
Comment #7
chera.jaswinder CreditAttribution: chera.jaswinder commentedok let me put each and everything in front of you.
I created a profile form using profile 2 module.
I need to show the same form on some another page so I used following code to show my form.
I altered my form using hook_form_alter() as mentioned earlier like removing submit button and providing my own submit buttons and its related functionality.
I added address field in while creating profile fields using address_field module.
If you are aware of address field module it provides us power to add another plugin so following is the plugin part which makes call to the ajax function known as addressfield_standard_widget_refresh
Called function looks like this which is contained in address_field.module file
All form alter setting done using hook_form_alter are removed. Speacilly i added one text field to a form using hook_form_alter().
Problem is:
Till the time I am submitting the form without making ajax hit it is working fine. Moment I make ajax hit and then re-submit the form submit button which was unset starts appearing and text field which i have added to form using hook_form_alter is removed.
I am not able to understand how to restrict all this? Its urgent please help. Hope it clears everything now.
Comment #8
chera.jaswinder CreditAttribution: chera.jaswinder commentedHey Jaypan,
It was my mistake at hook_form_alter().
Actually I have put some condition to call my alter function only if current path is equivalent to "verify/personal" path.
When we make ajax call it always set path to "system/ajax" due to which my alter conditions were not called. My bad.
Anyways, Thanks for your help. Keep doing great work.
Regards,
Jaswinder
Comment #9
Jaypan CreditAttribution: Jaypan at Jaypan commentedI'm glad you figured it out!
Comment #11
koushiknaikel CreditAttribution: koushiknaikel commentedI am new in drupal,
I am using this code bellow on tpl file.
but when I want to change country then Address field remove.
please help me what will be exact code ?