0

I have a webform as a block which sets a value connected to the logged in user. I want to display the webform if it hasn't been filled in yet by authenticated users, and hide it when it has (based on whether the value has been set or not).

I thought I could do it by using views with the Views Block Area to display the webform as a block when there is no result. But I want to hide the view when there is a result, which seems impossible?

If anyone can suggest how I might be able to achieve this, not necessarily using views.

  • Possible duplicate of drupal.stackexchange.com/questions/200595/… – prkos Jan 14 at 13:57
  • Thanks for pointing out the duplicate. I have used Rules Block Visibility before but was hoping to find an alternative. May just need to find a way to code it I guess. – Ben Jan 14 at 15:57
1

Limit submissions to "1 ever" when you configure the Webform. I'm not sure if Webform Block module would automatically hide the block if the form is not shown, but it should. Webform will not show the form if it cannot be submitted.

  • 1
    Many thanks for your answer. I had ended up using code (I gave this as an answer) but yours would have been a much easier way of solving it! I was thinking there must have been an easier way :) – Ben Jan 17 at 7:34
0

In the end I used code in the block page visibility settings to only show the block based on whether users had set a value in their CiviCRM profile (a Drupal module). I am posting the code in case it helps others:

<?php 

    civicrm_initialize( );

  //variable used to set if block should be displayed or not - default to not
    $show = 0;

    //get current logged in user civi id
    $contact = CRM_Core_Session::singleton()->getLoggedInContactID();

    //get employer id
    $org = civicrm_api3('Relationship', 'get', [
        'sequential' => 1,
        'return' => ["contact_id_b"],
        'relationship_type_id' => 5,
        'contact_id_a' => $contact,
    ]);

    if(isset($org['values'][0]['contact_id_b'])) {

        //get field value
        $result = civicrm_api3('Contact', 'get', [
            'sequential' => 1,
            'return' => ["custom_958"],
            'id' => $org['values'][0]['contact_id_b'],
        ]);

        // only show on the members home page
        if(drupal_get_path_alias() == 'members/organisation-profile') {
            $show = 1;
        }

        // don't show if they have set a value
        if(isset($result['values'][0]['custom_958'])) {
            $show = 0;
        }

        // do show if the value is ''
        if($result['values'][0]['custom_958'] == '') {
            $show = 1;
        }
    }

    return $show;

?>

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.