vol_pledge_form

<t:set id="_show_foodbanks" value="0" />

<t:if test="user.isanonymous != true">
  <t:if test="isGroupMember('137023')">
    <t:set id="_show_foodbanks" value="1" />
  </t:if>
</t:if>

<div class="banner-donation-form">
  <div class="promo-action">
    <form class="promo-learn">

      <t:if test="_show_foodbanks == 0">
        <!-- add first and last name fields -->
        <div class="banner-donation-level-container">
          <input class="campaign-email" type="text" name="cons_first_name" placeholder="First Name" value="">
        </div>
        <div class="banner-donation-level-container">
          <input class="campaign-zip" type="text" name="cons_last_name" placeholder="Last Name" value="">
        </div>
        <div class="banner-donation-level-container">
          <input class="campaign-email" type="email" name="cons_email" placeholder="Enter Email" value="">
        </div>
        <div class="banner-donation-level-container">
          <input class="campaign-zip" type="text" name="cons_zip_code" placeholder="Enter Zip" value="">
        </div>
        <div class="banner-donation-level-container">
          <button type="button" id="pledge-to-volunteer-bttn" class="red">PLEDGE TO VOLUNTEER</button>
        </div>
        <div class="clearfix"></div>
        <input name="survey_id" type="hidden" value="7804" />
      </t:if>

      <t:else>
        <input name="cons_primary_address_zip" type="hidden" value="">
      </t:else>

      <input name="cons_id" type="hidden" value="">
    </form><!--/.promo-learn-->
    <div id="pledge-to-volunteer-errors" class="error-block" style="display: none;"></div>

    <t:if test="user.isanonymous != true">
      <div id="logged-in">You are currently logged in as <t:value id=cons.name.first></t:value> <t:value id=cons.name.last></t:value>. Not <a href="https://secure.feedingamerica.org/site/UserLogin?logout=0&amp;NEXTURL=http://www.feedingamerica.org/includes/"><t:value id=cons.name.first></t:value> <t:value id=cons.name.last></t:value></a> ?</div>
    </t:if>

  </div>
</div>

<style>
  .error-block {
    color: #fff;
  }
  .promo-learn .find_local_food_bank_result {
    font-size: 18px;
    line-height: 24px;
    vertical-align: top;
    margin-bottom: 10px;
  }
  .promo-learn .find_local_food_bank_result .volunteer-url,
  .promo-learn .find_local_food_bank_result .volunteer-url a {
    font-size: 14px;
  }
  .promo-learn .find_local_food_bank_result a {
    /* text-transform: uppercase; */
    text-decoration: underline;
  }
  #logged-in {
    color: #fff;
    font-size: 10px;
    padding-top:10px;
  }
</style>

<script src="/assets/js/xml2json.js"></script>
<script src="/assets/js/xdr.js"></script>
<script src="/assets/js/fa-get.js"></script>

<script src="//cdnjs.cloudflare.com/ajax/libs/numeral.js/1.4.5/numeral.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/luminateExtend/1.7.1/luminateExtend.min.js"></script>

<script>
    if (typeof FA == 'undefined') { // Make sure FA namespace is initialized
      var FA = {};
    }

    FA.VolunteerSurvey = new (function() {
      this.options = {};
      this.luminateExtend = null;

      // Private properties
      var self = this;
      var $surveyForm = null;
      var $submitBttn = null;
      var $errorBox = null;

      var defaults = {
        submitBttnId: '',
        errorBoxId: '',
        errorBoxId: '',
        pledgeHeadlineId: '#pledge-headline-text',
        cons_id: $('#cons_id').val(),
        zip_code: '',
        group_id: '137023'
      };

      var formFields = {
        cons_first_name: 'First Name',
        cons_last_name: 'Last Name',
        cons_email: 'Email',
        cons_zip_code: 'Zip'
      };

      // Public methods
      this.process = function(luminateExtend, options) {
        self.luminateExtend = luminateExtend;
        self.options = $.extend({}, defaults, options);
        initSurvey();
      };

      // Private methods
      function initSurvey() {
        $errorBox = $(self.options.errorBoxId);
        $submitBttn = $(self.options.submitBttnId);
        $surveyForm = $submitBttn.closest('form');

        if ($submitBttn.length) {
          $submitBttn.click(function(e) {
            e.preventDefault();
            $errorBox.hide().empty();
            if (formValidation()) {
              submitSurvey();
            }
          });
        } else {
          var $foodbanksZip = $('input[name="cons_primary_address_zip"]');
          if ($foodbanksZip.length) {
            $surveyForm = $foodbanksZip.closest('form');
            self.options.zip_code = $foodbanksZip.val();
            if (self.options.zip_code != '') {
              showFoodbanks();
            } else {
              getProfile();
            }
          }
        }
      }

      function submitSurvey() {
        // Processing
        var formData = $surveyForm.serialize();
        self.luminateExtend.api({
          api: 'survey',
          requestType: 'POST',
          requiresAuth: true,
          callback: {
            success: function(response) {
              if (response.submitSurveyResponse) {
                if (response.submitSurveyResponse.success == 'false') {
                  var html = '', errors = returnArray(response.submitSurveyResponse.errors);
                  for (var i = 0 ; i < errors.length ; i++) {
                    if (formFields[errors[i].errorField]) {
                      html = html + formFields[errors[i].errorField] + ': ' + errors[i].errorMessage + '<br>';
                    }
                  }
                  $errorBox.html(html).show();
                } else {
                   var firstName = $surveyForm.find('input[name="cons_first_name"]').val();
                   increaseCount();
                   showFoodbanks();
                   changeHeadline(firstName);
                   window._fbq.push(['track', '6026389200849', {'value':'0.00','currency':'USD'}]);
                }
              }
            },
            error: function(response) {
              if (response.errorResponse) {
                if (response.errorResponse.message) {
                  $errorBox.html(response.errorResponse.message).show();
                }
              }
            }
          },
          data: 'method=submitSurvey&response_format=json&' + formData
        });
      }

      function formValidation() {
        var html = '', ok = true;
        $.each(formFields, function(key, value) {
          if ($.trim($surveyForm.find('input[name="' + key + '"]').val()) == '') {
            ok = false;
            html = html + value + ': You must provide a value for this field.<br>';
          }
        });
        if (ok) {
          ok = false;
          var zip = $.trim($surveyForm.find('input[name="cons_zip_code"]').val());
          if (zip.length > 4) {
            var zip = zip.substring(0, 5);
            if (zip == parseInt(zip)) {
              ok = true;
              self.options.zip_code = zip;
            }
          }
          if (!ok) {
            html = html + 'Zip: Please provide a valid zip code value.<br>';
          }
        }
        if (!ok) {
          $errorBox.html(html).show();
        }
        return ok;
      }

      function returnArray(data) {
        if (data.constructor == Array) {
          return data;
        } else {
          return [data];
        }
      }

      function increaseCount() {
        var $counter = $('div.meal-counter > strong');
        if ($counter.length == 1) {
          var num = numeral().unformat($counter.text());
          $counter.html(numeral(num + 1).format('0,0'));
        }
      }

      function changeHeadline(firstName) {
        var html =
        '<p style="font-size: 18px;"><strong>' + firstName + ', thank you for taking the pledge!</strong></p>' +
        '<p>Let your family and friends know that you took the pledge to volunteer and ask them to join you in the fight to end hunger – share on <a href="https://www.facebook.com/sharer/sharer.php?u=http://www.feedingamerica.org/take-action/volunteer/volunteer-with-your-local-food-bank/" title="Facebook" target="_blank">Facebook</a> or <a href="https://twitter.com/home?status=Pledge%20to%20volunteer%20at%20your%20local%20food%20bank%20and%20help%20millions%20of%20Americans%20struggling%20with%20hunger.%20feeding.am/volunteer%20%23FeedingAmerica%20" title="Twitter" target="_blank">Twitter</a> now.</p>' +
        '<p>Contact your local food bank to learn more about volunteer opportunities in your area.</p>';
        $(self.options.pledgeHeadlineId).html(html);
      }

      function showFoodbanks() {
        if (FA.ws) {
          $surveyForm.empty().append('<div class="loading-white"></div>'); // Loading...
          FA.ws.request('GetOrganizationsByZip', { zip: parseZip(self.options.zip_code) }, 'Organization', function(data) {
            var counter = 0;
            $surveyForm.empty();

            for (var key in data) {
              counter++;
              if (counter > 2) { return; } // Display only first two results

              var org = data[key];
              var profileUrlName = (org.FullName.replace(/ - /g, '-')).replace(/ /g, '-').toLowerCase();
              var profileUrl = '/find-your-local-foodbank/' + (profileUrlName.replace(/[&]/g, 'and')).replace(/[^a-zA-Z0-9-]/g, '') + '.html';

              $surveyForm.append([
                '<div class="find_local_food_bank_result">',
                  '<a href="', profileUrl, '">', org.FullName, '</a> &nbsp;&bull;&nbsp; ', org.MailAddress.City, ', ', org.MailAddress.State, '<br>',
                  '<span class="volunteer-url">Learn more about <a href="', org.VolunteerURL, '">volunteer opportunities</a> at this food bank.</span>',
                '</div>'
              ].join(''));
            }
            if (counter == 0) { // No results
              $surveyForm.append('This is an invalid zip. A valid U.S. zip is required');
            }
          }, function(response) { // Error
            $surveyForm.html('Our online search is not working at this time. To find out your food bank, please call us at 800.771.2303');
          });
        }
      }

      function getProfile() {
        // Processing
        var formData = 'cons_id=' + self.options.cons_id;
        self.luminateExtend.api({
          api: 'cons',
          requestType: 'POST',
          requiresAuth: true,
          callback: {
            success: function(response) {
              if (user = response.getConsResponse) {
                var zip = user.primary_address.zip;
                if (zip.length >= 5) {
                  self.options.zip_code = zip;
                  showFoodbanks();
                }
              }
            },
            error: function(response) {
            }
          },
          data: 'method=getUser&response_format=json&' + formData
        });
      }
    });

    function parseZip(zip) {
      if (zip.length > 4) {
        zip = zip.substring(0, 5);
      }
      return zip;
    }

    $(function() {
      luminateExtend.init({
        apiKey: 'B3AC0NF33D',
        path: {
          nonsecure: 'http://help.feedingamerica.org/site/',
          secure: 'https://secure.feedingamerica.org/site/'
        }
      });
      FA.VolunteerSurvey.process(luminateExtend, {
        submitBttnId: '#pledge-to-volunteer-bttn',
        errorBoxId: '#pledge-to-volunteer-errors'
      });
    });
</script>

<script>
(function() {
  var _fbq = window._fbq || (window._fbq = []);
  if (!_fbq.loaded) {
    var fbds = document.createElement('script');
    fbds.async = true;
    fbds.src = '//connect.facebook.net/en_US/fbds.js';
    var s = document.getElementsByTagName('script')[0];
    s.parentNode.insertBefore(fbds, s);
    _fbq.loaded = true;
  }
})();
window._fbq = window._fbq || [];
</script>

 

Stay Informed

Get email updates about what we're doing to help solve hunger and how you can help.