ui.imFeedBack – A JQuery UI Feedback Widget
Monday, July 5th, 2010When the web20.digitalvilliage site was nearly complete, I wanted to add a contact form. I like the feedback tabs that I have been seeing on websites recently (displayed on the right or left of the page), so I decided to build one. I was already using a JQuery UI theme on the site, so I decided to create a JQuery UI widget so that the color scheme of the feedback form would match the color scheme on the site.
This ui.imFeedBack widget is extremely versatile. The feedback tab can be placed on the right or left and can even be displayed as a dialog.
Creating a JQuery UI Theme
Before setting up the widget, create a theme with the JQuery UI Themeroller. I discuss the themeroller in a previous post.
Setting up the ui.imFeedBack Widget
First add the necessary CSS and JS files to the head section of your web page:
<link rel="stylesheet" type="text/css" href="css/jquery-ui/custom-theme/jquery-ui-custom.css" /> <link rel="stylesheet" type="text/css" href="css/imfeedback/imfeedback.css" /> <script type="text/javascript" src="js/jquery/jquery-ui/jquery-ui.js"></script> <script type="text/javascript" src="js/jquery/imfeedback/ui.imFeedBack-0.5.js"></script> |
The only option that is needed in order to use the ui.imFeedBack widget is the submit_url. This is the location of your server-side script that sends the email.
$(document).ready(function(){ $(document.body).imFeedBack({ submit_url: 'http://www.mysite.com/send_mail.php' }); }); |
This will create the FeedBack tab on the right of the page. When the user clicks on the tab, the feedback form will slide open. If I prefer to display the feedback tab on the left:
$(document).ready(function(){ $(document.body).imFeedBack({ location: 'left', submit_url: 'http://www.mysite.com/send_mail.php' }); }); |
Changing CSS Styles
The ui.imFeedBack widget is set up to automatically use a JQuery UI theme, but I set it up so that it can be styled independently. The following are the options that can be used to change the styling of the widget.
form_container_class: 'ui-widget ui-widget-content ui-corner-all' // The form buttons are the send and close buttons form_button_class: 'fg-button ui-state-default ui-corner-all' form_button_class_hover: 'ui-state-hover' // The header class is the caption container header_class: 'ui-widget-header ui-corner-top' // The feedback_button is the feedback tab that is displayed on the left or right feedback_button_class: 'fg-button ui-state-default ui-corner-top' feedback_button_class_hover: 'ui-state-hover' |
Sending the User’s Name
By default, the feedback form contains an email, subject, and message field. To display a name field, use the form_capture_name option. There are 4 possible values for this option:
false: Name fields are not displayed (the default)
firstName: A First Name field is displayed
fullName: A single input input field is displayed where the user can enter their full name
firstLast: First name and last name fields are displayed
$(document).ready(function(){ $(document.body).imFeedBack({ form_capture_name: 'firstName', submit_url: 'http://www.mysite.com/send_mail.php' }); }); |
The ui.imFeedBack widget will validate the form fields by default (value must not be blank and email must be correct format). You have the option of turning off the validation of the name field using the validate_name option.
$(document).ready(function(){ $(document.body).imFeedBack({ form_capture_name: 'firstName', validate_name: false, submit_url: 'http://www.mysite.com/send_mail.php' }); }); |
Setting Text Options
A number of text options can be set or changed. The following are the options with their default values:
header_caption: 'Please Send Us an Email' // The top_text is the area above the form field. Use this area to display any additional information or instructions top_text: '' // The feedback tab feedback_button_text: 'FeedBack' |
In addition, the subject field can be pre-filled. You can also set whether you want the subject field to be disabled.
feedback_subject: 'I love Stargate SG-1' // The disable_subject option is empty by default // To disable the field, set the option to true disable_subject: '' |
Displaying the FeedBack Form in a Dialog box
By default, when a user clicks on the feedback tab, the feedback form will slide into view. If you prefer to display a dialog box, set the show option to dialog (it is set to slide by default). You also have to give the dialog an id and set the width.
$(document).ready(function(){ $(document.body).imFeedBack({ show: 'dialog', dialog_container: 'imFeedBack-dialog', dialog_width: '550px', submit_url: 'http://www.mysite.com/send_mail.php' }); }); |
This dialog_container does not have to be styled, if you have not set the body’s font-size to 62.5%, you may want to set it here.
#imFeedBack-dialog { font-size: 62.5% } |
When using the dialog option, you also have the option of displaying your own form. Just set the dialog_widget_form option to false and then create your own form.
$(document).ready(function(){ $(document.body).imFeedBack({ show: 'dialog', dialog_container: 'my-dialog', dialog_widget_form: false, dialog_width: '550px', submit_url: 'http://www.mysite.com/send_mail.php' }); }); |
When using this option, make sure you name your form imFeedBack-FormContainer, so that it will be submitted correctly.
<div id="my-dialog"> <form name="imFeedBack-FormContainer" id="imFeedBack-FormContainer"> </form> </div> |
External Control
I set up the ui.imFeedBack widget so that it can be opened by a separate element on the page. Use this option if you want to display a specific feedback_subject and top_text options that are different from your site-wide feedback form. I created the web20.digitalvilliage.com site for marketing purposes. At the top of the page, I created a button with the text: Need A Web Developer?. When the user clicks on the button, the feedback form appears with the subject field pre-filled.
$(document).ready(function(){ $(document.body).imFeedBack({ top_text: 'For expert web design, contact us today', feedback_subject: 'I need a web designer', external_control: { id: 'stargateBtn', top_text: 'If you love Stargate SG-1, send us an email to tell us why.', feedback_subject: 'I love Stargate-SG1', disable_subject: true}, submit_url: 'http://www.mysite.com/send_mail.php' }); }); |
The external_control option has 4 values that can be set:
id: The id of the controlling element (Mandatory)
top_text: The text to be displayed above the form fields (optional)
feedback_subject: The text to be displayed in the subject field (optional)
disable_subject: Whether to disable the subject field (optional)
Once the feedback form is closed, the relevant values will be set back to the global options.
Submitting the Form
The feedback form will submit the following fields:
- imFeedBack-Email
- imFeedBack-Subject
- imFeedBack-Message
When using the form_capture_name option, the form will also submit:
- imFeedBack-FirstName (when option = firstName)
- imFeedBack-Name (when option = fullName)
- imFeedBack-FirstName, imFeedBack-LastName (when option = firstLast)
In addition to these values, you can send hidden fields, using the hidden_fields option:
$(document).ready(function(){ $(document.body).imFeedBack({ hidden_fields: [ {name: "message_type", value: "P"}, {name: "action", value: "doWhatever"}], submit_url: 'http://www.mysite.com/send_mail.php' }); }); |
The form is submitted ajaxally. The widget expects a Json record to be returned.
{"response": "Message Sent"} |
If “Message Sent” is the response, then the widget will display:
Thank you for contacting us. We will get back to you as soon as we can.
If “Message Sent” is not in the response, the widget will display the message sent back.
if ($success) { echo '{"response": "Message Sent"}'; } else { echo '{"response": "'. $errorMsg . '"}'; |
The success message can be changed by setting the success_msg option:
$(document).ready(function(){ $(document.body).imFeedBack({ success_msg: 'Thank you contacting us', submit_url: 'http://www.mysite.com/send_mail.php' }); }); |
Well that’s it. As you can see the ui.imFeedBack widget is extremely versatile, but simple to use. You can download the widget from GitHub. You can view demos of the widget in the JQuery UI Widgets demo section of my site. Enjoy.



July 5th, 2010 at 11:23 pm
Jquery feedback does not work on Opera 10.60
Regards
July 6th, 2010 at 12:57 am
Interesting. I’ll have to look more into it. It’s difficult to find exactly where it’s failing in Opera. It’s displaying an error that a function does not exist, but the function obviously does exist or the widget would not work in other browsers.
August 24th, 2010 at 5:11 pm
This definitely does not work in IE – neither 7 nor 8!
Any resolutions?
August 25th, 2010 at 10:45 pm
I just fixed the problem with ie (I tested it with IE8). I assume that this new version will work in Opera as well.
I was not able to upload it to jQuery’s repository, so you will have to get it from Google Code.
I also include two additional css files (ie_left.css and ie_right.css). Use IE conditionals to load the appropriate file. For now, each of these files only contain a single styling, so you can alternatively add the styling to the html page.
September 13th, 2010 at 4:27 pm
Thanks a lot! Will test in IE 7/8 and let you know if the issues persist.
October 8th, 2010 at 9:17 pm
Thanks for the widget code.
Can you share the basic send_mail.php code for receiving the POST data and sending out the json response?
thanks again !
November 18th, 2010 at 7:50 am
Hi,
I tried the new code and it’s working in IE8 but not in IE7 :s
any idea ?
January 14th, 2011 at 1:29 pm
Sorry for the late reply.
The Post vars are:
imFeedBack-Email
imFeedBack-Subject
imFeedBack-Message
If you use the name options, the additional feedback fields are:
First Name Only: imFeedBack-FirstName
or
Name: imFeedBack-Name
or
First and Last: imFeedBack-FirstName, imFeedBack-LastName
You can send a simple message back:
echo '{"response": "Message Sent"}';
January 17th, 2011 at 10:02 pm
I just created a new version of the plugin:
Version 0.5.2
I updated the code so that the widget works with IE7.
Download from Google Code or JQuery Plugins
February 1st, 2011 at 9:14 pm
Does this work with ui 1.8.9?
April 25th, 2011 at 4:06 pm
Thanks for the code first of all. Could you also share the send_mail.php code,as I am having difficulty in retrieving the values.
August 17th, 2011 at 3:29 pm
was looking how to make one of these cool widgets, but am having trouble understanding how to put it all together right now i have the index.html linking to the ui.imfeedback javascript file and the css file. could not find the jquery-ui.js file anywhere on your site or downloads. Is there more that i need to put into the html to get this widget to work?
December 30th, 2011 at 11:50 pm
I just upgraded the imFeedback widget to fix the problem with IE. The updated widget is stored on GitHub.