I have a regular drupal 7 form (based on a content type called guests) where I need a "Bring my partner" checkbox. When the checkbox is clicked, a field collection field (first name/last name/address) needs to be prefilled basing on the details for the currently logged-in user. (Partner details are in my user account details.)

Can this be done in hook_form_alter()? Is there any other way to achieve this?


You could do this with hook_form_alter and add a state to the field that needs to be hidden.

$form["first_name"] = array(
    "#states" => array(
        "invisible" => array(
            ":input[name='bring_parter']" => array(
                "checked" => FALSE,

What this does is hides the "first_name" unless "bring_partner" is checked. More info here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.