WordPress.org

Ready to get started?Download WordPress

Forums

WP-Polls
[resolved] Need help with adding Input Text field (15 posts)

  1. krieg
    Member
    Posted 2 years ago #

    Great job with this plugin Lester Chan,

    I need help with the following.
    Right now I am trying to create a poll using the poll templates with 2 input text fields, I need this for email harvesting from my users before voting, I will only need to asked them to fill Name and E-mail. Using the poll template below and added into wp template option

    <p style="text-align: center;"><strong>%POLL_QUESTION%</strong></p><div id="polls-%POLL_ID%-ans" class="wp-polls-ans"><ul class="wp-polls-ul">
    
    <label for="name" id="name_label">Name</label>
          <input type="text" name="name" id="name" size="30" value="" class="text-input" />
     <label for="email" id="email_label">Return Email</label>
          <input type="text" name="email" id="email" size="30" value="" class="text-input" />

    Sadly, tweaking the polls-js.js and jquery to read the #name and #email IDs are not working.
    I declared the variable and everything, tried using ajax to send the values to the php without success.

    var dataString = 'name='+ name;
    jQuery.ajax({
    type: 'POST', url: pollsL10n.ajax_url,
    data: dataString,
    cache:false,
    success: poll_process_success});

    on WP-POLL.PHP

    $name = $_POST["name"];
    $email = $_POST["email"];

    altered the database to include the name and email field, which works.

    $wpdb->query("INSERT INTO $wpdb->pollsip VALUES (0, $poll_id, $polla_aid, '$pollip_ip', '$pollip_host', '$pollip_timestamp', '$pollip_user', '$name', '$email', $pollip_userid)");

    However it fails to retrieve the value of the input on the form, and on wp-polls.php it will not read the string. I really dont know what to do to make it work.

    I areadly manage to add name and email columns in pollip database table.
    which loops on every vote but it will not populate the name and email table.

    I am using a test wordpress install on my pc using xampp, and with only wp=polls available. the idea show look like this on the widget.

    http://i48.tinypic.com/2ugc9s7.jpg

    Thanks in Advance,
    Krieg

    http://wordpress.org/extend/plugins/wp-polls/

  2. krieg
    Member
    Posted 2 years ago #

    I solved it...

  3. junobeach20
    Member
    Posted 2 years ago #

    Hi Krieg. I am looking to do the exact same thing and haven't gotten anywhere. Would you be interested in helping me out? My email address is jakecarney@mac.com

    Thanks!
    Jake

  4. wglassbrook
    Member
    Posted 2 years ago #

    I would also be interested in adding additional input fields into a poll. Perhaps a tutorial is in order?

  5. digitalrub
    Member
    Posted 2 years ago #

    I'm looking to do the exact same thing. How did you finally solve it?

  6. monweb
    Member
    Posted 2 years ago #

    I'm looking to do the exact same thing too. :\

  7. digitalrub
    Member
    Posted 2 years ago #

    ok, this is how i got it to work. Not saying this is the best way to do it, or even a good/secure way to do it - but it throws data in the table. I added my extra fields to polls_ip through phpmyadmin.

    I added my fields to the form footer in the template interface:

    <div id="frm_field_8_container" class="frm_form_field form-field  frm_required_field frm_top_container">
        <label class="frm_primary_label">NAME    </label>
        <input type="text" id="pollip_name" name="pollip_name" value="" class="texty"></div>
    
    <div id="frm_field_9_container" class="frm_form_field form-field  frm_required_field frm_top_container">
        <label class="frm_primary_label">EMAIL  </label>
        <input type="text" id="pollip_email" name="pollip_email" value="" class="text required">
     </div>
    
    <div id="frm_field_10_container" class="frm_form_field form-field  frm_required_field frm_top_container">
        <label class="frm_primary_label">ZIP CODE</label>
        <input type="text" id="pollip_zipcode" name="pollip_zipcode" value="" class="text required">
    </div>
    <div id="frm_field_12_container" class="frm_form_field form-field  frm_required_field frm_top_container">
        <label class="frm_primary_label">CURRENT CARRIER    </label>
        <input type="text" id="pollip_carrier" name="pollip_carrier" value="" class="text required">
    </div>

    Then I changed the polls-js.js to the polls-js.dev.js in wp-polls.php.

    Then in polls-js.dev.js at line 19:

    var pollip_name = '';
    var pollip_email = '';
    var pollip_zipcode = '';
    var pollip_carrier = '';

    Under this function jQuery('#polls_form_' + poll_id + ' input:checkbox, #polls_form_' + poll_id + ' input:radio').each(function(i) I added:

    jQuery('.texty').each(function(){
    
    				pollip_name = jQuery('#pollip_name').val();
    				pollip_email = jQuery('#pollip_email').val();
    				pollip_zipcode = jQuery('#pollip_zipcode').val();
    				pollip_gender = jQuery('#pollip_gender').val();
    				pollip_carrier = jQuery('#pollip_carrier').val();
    
    		});

    Then in wp-polls.php line 1305:

    $pollip_name= $_POST["pollip_name"];
      $pollip_email= $_POST["pollip_email"];
      $pollip_zipcode= $_POST["pollip_zipcode"];
      $pollip_carrier= $_POST["pollip_carrier"];

    Then updated this query to include my fields:

    INSERT INTO $wpdb->pollsip VALUES (0, $poll_id, $polla_aid, '$pollip_ip', '$pollip_host', '$pollip_timestamp', '$pollip_user', $pollip_userid, '$pollip_name', '$pollip_email', '$pollip_zipcode', '$pollip_carrier')

  8. monweb
    Member
    Posted 2 years ago #

    Thanks a lot digitalrub.
    I gonna try this in the afternoon.

  9. monweb
    Member
    Posted 2 years ago #

    Just to say you forgot to tell me to add the data in the jQuery.ajax function in polls-js.dev.js ;)
    It work fine thank you.

  10. digitalrub
    Member
    Posted 2 years ago #

    oh yeah, that would have been helpful...

  11. mhoard8110
    Member
    Posted 1 year ago #

    digitalrub,

    can you shed more light on what monweb is referring to? which jQuery.ajax function do I add the data?

  12. monweb
    Member
    Posted 1 year ago #

    Hello mhoard8110,

    The 2 jQuery.ajax functions you have to modify are in the "// Process Poll (User Click "Vote" Button)" section (line 80/100).
    You just have to add + '&pollip_name=' + pollip_name + '&pollip_email=' + pollip_email etc. after poll_id + '_nonce=' + poll_nonce into the functions.

  13. digitalrub
    Member
    Posted 1 year ago #

    Yeah, that's it. Thanks, monweb.

  14. mhoard8110
    Member
    Posted 1 year ago #

    Thanks for the reply monweb. Another quick question. What about making these fields required.

  15. digitalrub
    Member
    Posted 1 year ago #

    this is how i did it:

    you'll need to add alerts to the wp-polls. php

    wp_localize_script('wp-polls', 'pollsL10n', array(
    		'ajax_url' => admin_url('admin-ajax.php', (is_ssl() ? 'https' : 'http')),
    		'text_wait' => __('Your last request is still being processed. Please wait a while ...', 'wp-polls'),
    		'text_valid' => __('Please choose a valid poll answer.', 'wp-polls'),
    		'text_name' => __('Please enter your name.', 'wp-polls'),
    		'text_tandc' => __('Please accept the terms and conditions.', 'wp-polls'),
    		'text_email' => __('Please enter a valid email address.', 'wp-polls'),
    		'text_carrier' => __('Please enter your current mobile carrier.', 'wp-polls'),
    		'text_multiple' => __('Maximum number of choices allowed: ', 'wp-polls'),
    		'show_loading' => intval($poll_ajax_style['loading']),
    		'show_fading' => intval($poll_ajax_style['fading'])
    	));

    and then in polls-js

    if(poll_multiple_ans > 0) {
    			if(poll_multiple_ans_count > 0 && poll_multiple_ans_count <= poll_multiple_ans) {
    				poll_answer_id = poll_answer_id.substring(0, (poll_answer_id.length-1));
    				poll_process();
    			} else if(poll_multiple_ans_count == 0) {
    				set_is_being_voted(false);
    				alert(pollsL10n.text_valid);
    			} else {
    				set_is_being_voted(false);
    				alert(pollsL10n.text_multiple + ' ' + poll_multiple_ans);
    			}
    		} else {
    			 if(pollip_name == '') {
    				set_is_being_voted(false);
    				var name_alert = pollsL10n.text_name + "\n";
    			} else{var name_alert = ''}
    
    			if(pollip_email == '') {
    				set_is_being_voted(false);
    				var email_alert = pollsL10n.text_email + "\n";
    			} else{var email_alert = ''}
    
    			if(pollip_carrier == '') {
    				set_is_being_voted(false);
    				var carrier_alert = pollsL10n.text_carrier + "\n";
    			} else{var carrier_alert = ''}
    
    			if(pollip_rules !== 1) {
    				set_is_being_voted(false);
    				var tandc_alert = pollsL10n.text_tandc;
    			} else{var tandc_alert = ''}
    
    			if(poll_answer_id > 0 && pollip_name !== '' && pollip_email !== '' && pollip_carrier !== '' && pollip_rules == 1) {
    				poll_process();
    			} else {
    				set_is_being_voted(false);
    				alert(pollsL10n.text_valid + "\n" + name_alert + email_alert +  carrier_alert + tandc_alert);
    			}
    		}
    	} else {
    		alert(pollsL10n.text_wait);
    	}
    }

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic