Click here to Skip to main content
15,886,055 members
Articles / Programming Languages / PHP

Bug Submitter Dialog

Rate me:
Please Sign up or sign in to vote.
3.67/5 (5 votes)
28 Apr 2009GPL33 min read 35.5K   411   29   6
Dialog that enables user to submit various types of bugs via a webservice

Introduction

This dialog enables user to submit various types of bugs with build in validation. The submitted information is then sent to a webservice.

bugreporter_form.gif

Background

I have a few small applications that I developed to improve my coding knowledge. An easy way for users to submit feedback on my applications and report bugs would be very useful in all of them. I created this dialog for this purpose, while keeping in mind that it should be stable, user friendly, and very easy to implement in any of my applications.

Using the Code

The dialog itself can be integrated without much work into your application, but the webservice will require some attention.

Here you have a simple example of showing the dialog:

VB.NET
With New BugSubmitter
    .SubmitterFile = "BN+converter-pro.php"
    .SubmitterPath = "http://service.bn2vs.com/bugs"
    .ApplicationVersion = GetAppVersion("[M].[m].[b].[r]")

    .ShowDialog()
End With

GetAppVersion is a simple sub that returns the application version formatted as a string. You can also manually get the version data or use a static value.

VB.NET
''' <summary>Returns the version of the application</summary>
''' <param name="format">The format of the version.
''' [M]: Major
''' [m]: Minor
''' [b]: Build
''' [r]: Revision</param>
Public Function GetAppVersion(Optional ByVal format As String = _
						"v[M].[m].[b]") As String
    With My.Application.Info
        GetAppVersion = format.Replace("[M]", .Version.Major.ToString)
        GetAppVersion = GetAppVersion.Replace("[m]", .Version.Minor.ToString)
        GetAppVersion = GetAppVersion.Replace("[b]", .Version.Build.ToString)
        GetAppVersion = GetAppVersion.Replace("[r]", .Version.Revision.ToString)
    End With
End Function 

That's all the code you need to display the dialog! Now let's have a closer look at some of the properties.

Before the bug report is submitted, the information is validated. This can be either done with an error provider when the user hits the submit button, or with live validation that will only enable the submit button when all fields are valid.

VB.NET
''' <summary>Gets or sets if an error provider should be used 
''' to notify a user of errors.
''' When false, live validation will only enable the submit button when all fields 
''' are valid</summary>
Public Property UseErrorProvider() As Boolean
    Get
        Return m_useErrorProvider
    End Get
    Set(ByVal value As Boolean)
        m_useErrorProvider = value
    End Set
End Property

The dialog has some events related to the submission progress, but you don't need to bother about these in most cases. There are three steps in the submission progress:

  1. Creation of the bug report (see screenshot at the top of this article)
  2. Submission
  3. Success screen (see screenshot underneath) 

Every state will be clearly indicated to the user.

bugreporter_complete.gif

Now you can work with the dialog and understand how it works. Let's have a look at the webservice.  

The Webservice

In my applications, I have chosen to use a PHP webservice that generates an email with the submitted data and then sends it over to my inbox. The example here follows the same principle, but keep in mind you can handle the submitted data any way you want, like for example storing it in a database. Also note you can use ASP or any other server script to write the webservice in.

This is a little script I created to easily construct multiple email webservices for different applications: 

<?php

/**
 * BN+ bug report mailer
 * 
 * common.php
 * Version 1.0.0
 * 
 * By De Dauw Jeroen - jeroendedauw@gmail.com
 * April 2009
 */

// Deny access when one of the arguments is not provided
if (empty($_GET['type']) || empty($_GET['description']) || 
		empty($_GET['version'])) die("Hack attempt");

// Get the URL arguments
$type = $_GET['type'];
$description = str_replace("[amp]", "&", $_GET['description']);
$email = strlen($_GET['email']) > 0 ? $_GET['email'] : "None provided";
$version = $_GET['version'];

// Include the phpmailer class
require_once '../includes/phpMailer/class.phpmailer.php';

// Create a new instance of a phpmailer
$mail = new PHPMailer();  

// Set the sender data
$mail->From     = "bug-report@your-server.com";  
$mail->FromName = "Bug reporter @ your-server.com";    

// Create the mail with a simple layout
$body = "
<table border='1' width='100%'>

<tr bgcolor='gray'>
<td colspan='2'><u>Bug report for $app_name</u></td>
</tr>

<tr><td width='200'>Application version:</td><td>$version</td></tr>

<tr><td>Bug type:</td><td>$type</td></tr>

<tr><td>Bug description:</td><td>$description</td></tr>

<tr><td>User email:</td><td>$email</td></tr>

<tr bgcolor='gray'>
<td colspan='2'>Report send on ".date("F j, Y, g:i a")." (unix: ".time().")</td>
</tr>

</table>
";

// Set the mail subject, body and the address of the receiver(s)
$mail->Subject = "$mail_subject $type"; 
$mail->Body    = $body;  
$mail->AltBody = "Your client does not support html emails. Data cannot be accessed.";  
$mail->AddAddress("your-mail@your-server.com", "yourName"); 

// Send the email, and display either a success message and the mail contents, 
// or in case of failure the error details
// Displaying this is not required. You can also just send the mail with $mail->Send()
if ($mail->Send()) {
    echo "Mail send successfully.<br />\n\n\n\n\n\n\n\n";
    echo $body;
}
else {
    echo "Error sending mail. ".$mail->ErrorInfo;
}

?> 

A mail sent by this script will look similar to this one: 

bugReporter-email.gif

Now only a few lines of code are needed for each BugSubmitter:

<?php

/**
 * BugSubmitter demo bug report mailer
 * 
 * your-application-webservice.php
 * Version 1.0.0
 * 
 * By De Dauw Jeroen - jeroendedauw@gmail.com
 * April 2009
 */

$app_name = "BugSubmitter demo application";
$mail_subject = "BUG REPORT: BugSubmitter demo:";

require_once 'common.php';

?>

Note that in this example, I assume you are either using this webservice only once, or sending all mails to the same address. If this is not the case, you can easily add a new variable in your-application-webservice.php, before you include common.php, containing the address for that webservice, and then add it to the mailer address list in common.php

Points of Interest  

This was a nice exercise for me in creating a .NET dialog that loosely communicates with a webservice. I'm very happy with the result, and I'm now using this dialog in all of my .NET applications. I also got quite some positive feedback from people, and the request to better document this dialog, which prompted me to create this article.

History

  • April 28th 2009: Published article on The Code Project with webservice example
  • April 13th 2009: Published version 1.0.0 

References

  • Dutch support for this class can be found here.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


Written By
Software Developer
Belgium Belgium
I am a free and open source software enthusiast and freelance software developer with multiple years of experience in both web and desktop development. Currently my primarily focus is on MediaWiki and Semantic MediaWiki work. I'm in the all time top 10 MediaWiki comitters and am one of the WikiWorks consultants. You can contact me at jeroendedauw at gmail for development jobs and questions related to my work.

More info can be found on my website [0] and my blog [1]. You can also follow me on twitter [2] and identi.ca [3].

[0] http://www.jeroendedauw.com/
[1] http://blog.bn2vs.com/
[2] https://twitter.com/#!/JeroenDeDauw
[3] http://identi.ca/jeroendedauw

Comments and Discussions

 
GeneralGREAT!!! Pin
Anthony Daly25-May-09 1:54
Anthony Daly25-May-09 1:54 
GeneralRe: GREAT!!! Pin
Jeroen De Dauw25-May-09 22:04
Jeroen De Dauw25-May-09 22:04 
Generalnice work Pin
Donsw19-May-09 4:44
Donsw19-May-09 4:44 
GeneralRe: nice work Pin
Jeroen De Dauw25-May-09 22:02
Jeroen De Dauw25-May-09 22:02 
GeneralLicence Pin
James D. Weston10-May-09 10:22
James D. Weston10-May-09 10:22 
GeneralRe: Licence Pin
Jeroen De Dauw25-May-09 22:00
Jeroen De Dauw25-May-09 22:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.