Jesse J Heap & Son, Inc.
 

Home » Adding additional fields to wordpress/phplist plugin

Adding additional fields to wordpress/phplist plugin

Nick from www.NicksJourney.com asked the following question regarding my wordpress/phplist plugin:

How can I add more attributes other than Name and Email? (like Zip code, for example) – see my phpList Capture page at www.nickdaugherty.com/lists/

This is a common request from users, many want the ability to add additional customizable fields to wordpress/phplist plugin. By default the plugin only offers one customizable field in addition to the default email field.

The following hack provides a fairly easy way to extend the script to support more fields. The hack does assume a general understanding of HTML form elements. In the future I’ll work on making this option available through the admin menu.

Instructions on how to add additional fields to wordpress/phplist plugin:

1. Open up phplist.php (located in plugins folder on your server) and at or around line 423 located the following code:

<form action="" method="post">

2. Underneath the form line you can add as many fields as you want. For example, in Nick’s case he wanted fields for first name, last name, zip code and state. The easiest way to do this is to open up your phplist subscriber page and copy the html for the input fields. Here is the code I added to support Nick’s requirements which was copied directly from www.nickdaugherty.com/lists/

<form action="" method="post">
                            <div class="contactleft"><label for="email">‘ . __($email_name, ‘phplist‘) . ‘</label></div>‘ . $phplist_strings['email'] . ‘
                                <!– START CUSTOM FIELDS –>
                                <div class="contactleft"><label for="attribute1">First Name</label></div>
                                <div class="contactright"><input type=text name="attribute1"  class="attributeinput" size="40" value=""></div>
                                <div class="contactleft"><label for="attribute2">Last Name</label></div>
                                <div class="contactright"><input type=text name="attribute2"  class="attributeinput" size="40" value=""></div>
                                <div class="contactleft"><label for="attribute4">State</label></div>
                                <div class="contactright"><select name="attribute4" class="attributeinput"><option value="1" >Alabama<option value="2" >Alaska<option value="3" >Arizona<option value="4" >Arkansas<option value="5" selected>California<option value="6" >Colorado<option value="7" >Connecticut<option value="8" >Delaware<option value="9" >Florida<option value="10" >Georgia<option value="11" >Hawaii<option value="12" >Idaho<option value="13" >Illinois<option value="14" >Indiana<option value="15" >Iowa<option value="16" >Kansas<option value="17" >Kentucky<option value="18" >Louisiana<option value="19" >Maine<option value="20" >Maryland<option value="21" >Massachusetts<option value="22" >Michigan<option value="23" >Minnesota<option value="24" >Mississippi<option value="25" >Missouri<option value="26" >Montana<option value="27" >Nebraska<option value="28" >Nevada<option value="29" >New Hampshire<option value="30" >New Jersey<option value="31" >New Mexico<option value="32" >New York<option value="33" >North Carolina<option value="34" >North Dakota<option value="35" >Ohio<option value="36" >Oklahoma<option value="37" >Oregon<option value="38" >Pennsylvania<option value="39" >Rhode Island<option value="40" >South Carolina<option value="41" >South Dakota<option value="42" >Tennessee<option value="43" >Texas<option value="44" >Utah<option value="45" >Vermont<option value="46" >Virginia<option value="47" >Washington<option value="48" >West Virginia<option value="49" >Wisconsin<option value="50" >Wyoming</select></div>
                                <div class="contactleft"><label for="attribute3">Zip Code</label></div>
                                <!– END CUSTOM FIELDS –>
                                <div class="contactright"><input type=text name="attribute3"  class="attributeinput" size="40" value=""></div>
                                ‘ . $txt_optional_field . ‘

                                        <div class="contactright"><input type="submit" name="Submit" value="’ . __(’Submit’, ‘phplist’) . ‘" id="contactsubmit" /><input type="hidden" name="phplist_submit" value="process" /></div>
                                    
                                </form>

Note: The key is to ensure the name attribute of the input tag corresponds with the correct name in phplist. This can be done by copying the HTML directly from your phplist subscriber form.

3. After adding the appropriate fields, go into the Wordpress/PHPList admin menu for my plugin and ensure the one custom field is unchecked.




Please select the newsletters you want to sign up for:
  • Main List
  • Spanish List
 

5 Responses to “Adding additional fields to wordpress/phplist plugin”

  1. KarthiKeyan Says:

    ok.. it is fair enough for zip code and state.. is there any generalized plugin or patch for adding any kind of fields?

    thanks
    learn & share security information
    and become a security expert.
    http://secureslash.com

  2. webmaster Says:

    Karthi - To clarify this post is related to adding additional fields when integrating phplist with wordpress. It is NOT for adding custom fields in wordpress.

    With that being said, I’m looking to add this functionality to my phplist plugin to easily support additional fields, but I don’t have any ETA. There are other wordpress/phplist plugins out there. Do a search on google and let me know if you find one that works for you.

    Otherwise, if you are feeling adventurous, it’s fairly easy to add any type of field elements. Just take a look at the form elements generated by phplist and copy them as mentioned above. And if all you are doing is adding text fields like above, you can simply change the name of the labels to match your fields.

    Like your site by the way.

    Jesse

  3. Nico Says:

    Hey Jesse,
    Both the vid and the example are very useful for people like me, i only have a vague notion on html.
    I’m having trouble with the use of checkboxes. I added an attribute in phplist as ‘group of checkbox’, among other ‘textline’ attributes. When i edit the phplist.php file, i don’t know how to add the checkbox to make it work properly.
    Right now i’m using:
    input type=checkbox name=”attribute6″ class=”attributeinput” value=”1″ > blah blah 1
    input type=checkbox name=”attribute6″ class=”attributeinput” value=”2″ > blah blah 2
    input type=checkbox name=”attribute6″ class=”attributeinput” value=”3″ > blah blah 3

    The problem is that if more than one checkbox is chosen, only the latest value is saved (ie. if i check N°1 and N°3, when i check the user info in phplist, only N°3 appears to have been chosen. If i check N°1 and N°2, only N°2 appears to have been chosen)
    I also tried with name=”attribute6[]“, but then nothing happens.
    I hope you can help me, eventhough this has hardly anything to do with your lifesaving plugin.
    Thanks a lot!
    cheers!

    Nico - This is likely and issue with the phplist.php and how it handles checkboxes. I’ll have to take a deeper look when I get a chance

  4. PHPList + Wordpress — BlogYourOwnBusiness.com Says:

    [...] JesseHeap have discover the whole plugin script and you want to make the form with additional function you can go to the site to find it out. [...]

  5. Jonas Bendsen Says:

    Hi, Jesse. Thanks for adding documentation for this function.

    However, your example code shows code in a format that doesn’t exist with the new PHPList. I think they started using Java to create labels instead of simply hard coding it, etc… I’m pretty sure we’ve got it figured out, but I just wanted to let you know.

    Also, it would be helpful if the PHPlist.php file for your plugin simply contained comment tags notifying where to inject the custom fields. I’m just having a little trouble making sure I stick the code in the proper place. I think this would be an easy thing to do that would really make it easy for people to add more custom fields.

Leave a Reply