0

I have created a content type with CCK on Drupal 7, and I would like to display only a few fields according to certain values in their profile2 type.

Concretely, I have a profile2 field to specify if the member is VAT registered or not. When the members are submitting their invoices, I want to display specific fields if they are VAT registered.

1

for this you have to create a field on your content type called vat registered or not. Autofill that field from profile 2 field for the specific users. Then use conditional module. If that field is filled by default show some fields otherwise do not show that fields.

  • 1
    Could you please elaborate? – Mołot Aug 1 '14 at 11:24
  • for this you have to create a field on your content type called vat registered or not . and autofill that field from profile 2 field for the specific users. and then use conditional module .if that field is filled by default show some fields otherwise do not show that fields. – harsh_behl_0007 Aug 1 '14 at 11:33
  • 1
    Please use edit button next time. – Mołot Aug 1 '14 at 11:36
0

you will likely need to use hook_form_alter in a custom module. The simplest way is to create the ecommerce section WITH the VAT fields as default, and then hide the fields if a condition is met (the profile doesn't contain the VAT). exactly how depends on field names and a few variables like accessing profile2 info that I'm not sure about, but this is the basic setup I think:

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

    // get Devel module(https://www.drupal.org/project/devel) for this line
    dpm($form_id);
    // this will output information on ALL forms - remove when complete, but use this to
    // get the correct form machine name if you can't find it elsewhere, as well as 
    // determining the correct structure of the form in order to hide the fields further down

    switch ($form_id)  {
        case 'ecommerce_form':
            // pull data on $user (global $user)
            // you may need to use some direct db access (https://api.drupal.org/api/drupal/includes!database!database.inc/function/db_select/7)
            // to get profile2 info (I don't remember if it links into $user directly or not)
            // if statement - if field in profile contains value (assuming a boolean)
            // if so, do nothing (VAT is set to visible by default)
            // if not, hide VAT fields
            break;
     }
  }

do a simple search for modifying a form (hiding an element), there are thousands of examples and tutorials out there.

helpful link: Form API - reference on form manipulation

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.