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.

10 Comments

  1. 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

  2. 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

  3. 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.

  4. Howdy Jesse

    Any chance you are in the middle of releasing your newest version of this excellent plugin?

    It would be nice to have the latest and greatest for a WordPress blog I want to upgrade to.

    I am particularly interested in being able to have widgets and more fields.

    The field is wide open for someone with talent like yours. The other WordPress PHPList combos are not up-to-speed…either.

    Yours seems the most promising…

    Hope to hear soon.

    Barefoot Ted

  5. Hey Ted,Thanks for your message and compliments, but unfortunately with work and our cake business I do not have the time to devote to enhancing these plugins any further…

  6. You can also customize the ” Thank you for subscribing” message that comes after a user sings . open the phplist.php file and find the function
    function phplist_widget($args)

    and then few line down down at this line:
    echo(“” . __(‘Thank You For Subscribing.’, ‘phplist’) . “”);
    change the – thank you statement – according to your need. For example if you want to warn the user that you will send him a confirmation email.

    thank you

  7. The string to add custom fields now starts at line 579, the code is
    $form = ‘

    ‘ . $phplist_strings[‘error’] . ‘
    ‘ . $txt_optional_field . ‘
    ‘ . __($email_name, ‘phplist’) . ”.$labelBreak. $phplist_strings[’email’] . ‘
    ‘. phplist_generate_list_elements() . ‘

    CUSTOM CODE MAY BE ADDED HERE.

    I Didn’t try out if the form’s data is present in the list’s database, but inserted code appears on the page.

    regards,
    johannes

  8. Hi. I have this working with custom fields, but my custom fields FirstName and LastName, which are required in my PHPList implementation, are not working as such. The record will not be written into PHPList if those required fields are not filled out (that’s good), but there’s no feedback to the user that a required field wasn’t filled out, and the user gets a “success” statement. Wen all fields are filled out, the record is properly entered into the PHPList database.

    I’ve added class=”required” into my custom fieldcode, perhaps I’ve done that wrong. here is the code for the FirstName field:

    First Name

    Any thoughts? Thx. Andy

Leave a Reply

Your email address will not be published. Required fields are marked *