Support » Plugin: WP-Polls » [Plugin: WP-Polls] Need help with adding Input Text field

  • Resolved krieg


    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;
    type: 'POST', url: pollsL10n.ajax_url,
    data: dataString,
    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.

    Thanks in Advance,

Viewing 14 replies - 1 through 14 (of 14 total)
  • I solved it…

    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


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

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

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

    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 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 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">

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

    Then in 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:

    				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')

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

    Just to say you forgot to tell me to add the data in the jQuery.ajax function in 😉
    It work fine thank you.

    oh yeah, that would have been helpful…




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



    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.



    Yeah, that’s it. Thanks, monweb.

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

    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));
    			} else if(poll_multiple_ans_count == 0) {
    			} else {
    				alert(pollsL10n.text_multiple + ' ' + poll_multiple_ans);
    		} else {
    			 if(pollip_name == '') {
    				var name_alert = pollsL10n.text_name + "\n";
    			} else{var name_alert = ''}
    			if(pollip_email == '') {
    				var email_alert = pollsL10n.text_email + "\n";
    			} else{var email_alert = ''}
    			if(pollip_carrier == '') {
    				var carrier_alert = pollsL10n.text_carrier + "\n";
    			} else{var carrier_alert = ''}
    			if(pollip_rules !== 1) {
    				var tandc_alert = pollsL10n.text_tandc;
    			} else{var tandc_alert = ''}
    			if(poll_answer_id > 0 && pollip_name !== '' && pollip_email !== '' && pollip_carrier !== '' && pollip_rules == 1) {
    			} else {
    				alert(pollsL10n.text_valid + "\n" + name_alert + email_alert +  carrier_alert + tandc_alert);
    	} else {

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘[Plugin: WP-Polls] Need help with adding Input Text field’ is closed to new replies.