3

Salut!

I have been working on a 100% non-profit project for 1 month and now I am facing a problem with the main feature that this project offer for free.

The project is a website about people willing to help other for free so there are two roles on the website: Job helper and Job Seeker

When someone register under the role of Job helper, he will be asked to verify his phone number and email address because at any time he might receive email/sms asking him for help.

When someone register under the role of Job seeker, he will be able to see a list of all available Job helper using a view display and then choose one from two options:

  1. A button or link to Send emails to all the available listed Job helper profiles, or
  2. A button or link to send email to only selected Job helper profiles.

Problem:

How to create such functionality, note that the view is already created and displaying all available users which are registered under the Job helper role but I cannot find a way to place a button or link within the view as well as check box near to every user so a Job Seeker can select all or select few profiles and send a customized email.

Solutions:

1) Using VBO, is possible to do the above, however after selecting users to send emails for them, I want the Job Seeker to be able to customize only the message body being sent, but VBO will display all the field shown in the picture below which will confuse the user of the website.

VBO

I want to display only the message text body so the Job Seeker can customize his own message like:

"We need help in cleaning the beach of Florida from any garbage at 14:00 tomorrow 15/Jun/2017, please be there for the beach"

Note the Job Seeker will have to write no recipient and no subject just a message text about the job.

2) I have an idea about using flag module with views, and so the Job Seeker will have to flag every single Job Helper and then write a customized message body to be send via email... But I really have no ideas from where I should start ?

Please note that I need to integrate rules with the solution because if every Job Seeker has the right to send 1000 emails per weeks and so I want to use rules to "-1" for every email being sent by a specific Job Seeker user.

Any suggestion and help will be much appreciated ! Thank you,

1 Answer 1

0

I wrote an answer somewhat similar to this functionality.

https://drupal.stackexchange.com/a/195228/53677

Basically, you could create an entityform with an entityreference field for emailable users and a field for your email message.

Then on your view page, provide an email button and use jQuery to create a link to pre-populate the users you want to email. Use Rules to loop this on entityform save.

The link to the form would have to look like /eform/submit/email-form?field_email_uids=10,12,15,201

It's a bit more work but can give a really nice interface if done right. Your view can be anything as long as you can grab the UIDs.

Or you could just hide the fields you don't want with css / jQuery.

Edit: Adding instructions for the jQuery part

Here's a very basic example of the finished result. This can be added to any view setup.

enter image description here

You can of course decide to not use checkboxes and perhaps add a border or background etc. to the whole row. You can do anything you like with jQuery and .parent()etc. to go up the DOM and add/remove classes.

Views Custom Text Field: (The UID and Name fields are hidden above. I use font-awesome on this install. You can use ✓ or something else instead of the )

<a href="#" class="email_box" value="[uid]">
<i class="fa fa-check"></i></a>
<span> [name] </span>

Views Footer Custom Text Field:

<a href="/eform/submit/email-form" id="email_link">Send Email</a>

jQuery:

$('.email_box').click( function() {

    // Check if it's clicked + add / remove classes
    if ( !$(this).hasClass('email_checked') ) {
        // Add Class
        $(this).addClass('email_checked');
    } else {
        // Remove Class
        $(this).removeClass('email_checked');
    }

    // Call function below for Email Link
    build_link();

});

// Get all boxes that are clicked and add their value tags to the link
var build_link = function() {
    var email_uids_array = [];
    // Loop checked and add UIDs to array
    $('.email_checked').each( function() {
        email_uids_array.push( $(this).attr('value') );
    });
    // Split array into uids
    var uids = email_uids_array.toString();
    // Create link
    var link = '/eform/submit/email-form?field_email_uids=' + uids;
    // Alter the Email link's href
    $('#email_link').attr('href', link);
};

Some CSS so it makes sense to the user:

.email_box {
  border: solid;
  border-width: 1px;
  border-color: #c2c2c2;
  color: #ddd;
}
.email_checked {
  color: #444;
}
/* Fix Hover / Focus */
.email_box:focus,
.email_box:hover {
  color: #ddd;
}
.email_checked:focus,
.email_checked:hover {
  color: #444;
}

The benefits here are total customization and it should work pretty well.

6
  • Thank you for your kind answer, can you please further explain with details how to achieve my needs with entityform ? and I am more experienced with webform than entityform so do you think is possible to create what you explained using Webform instead of Entityform ?
    – user76590
    Commented Jun 15, 2017 at 5:28
  • I've never used Webform so I don't know. But if you can add an entity reference field to a Webform and if Webform integrates well with Rules, it should work. (I really should play with Webform for an hour so I know more about it) Are you comfortable enough with jQuery do you think for this? Commented Jun 15, 2017 at 5:49
  • There is another solution involving a sandbox and a patch that allows you to put your view in a form with selectable rows. Great functionality but I don't like recommending sandbox projects. Commented Jun 15, 2017 at 5:52
  • After trying hours with Webform module, the problem I am facing now is how to tell the webform to use the selected rows (emails) and send email for them. I have managed to create a webform and so after visit the view and select as much row as he wants, here should be a link to open the webform and transfer those selected rows to it and then the user on the webform will write the email message and hit submit !
    – user76590
    Commented Jun 15, 2017 at 18:57
  • I think the answer to create the link tot he webform is here: Provide an email button and use jQuery to create a link to pre-populate the users you want to email. Use Rules to loop this on entityform save. The link to the form would have to look like /eform/submit/email-form?field_email_uids=10,12,15,201 can you please give more details on this one
    – user76590
    Commented Jun 15, 2017 at 18:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.