User friendly ’field missing’ warnings for comment form
Posted: 08 May 2006 11:36 AM   [ Ignore ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  371
Joined  10-18-2004

I’m trying to make the following work:

If a guest user leaves a comment, he/she has to fill in all required fields. Required fields are (in this case) Name, Email, URL, Location and Comment. If that user neglects to fill in any of those fields, the comment form should re-appear, but this time with notifications next to the input fields—something like ‘It is required that you fill in this field’.

In the way EE works now, if you ‘forget’ to fill in required fields, the user gets a plain error message, including a JavaScript link to go back. Works in a basic way, but there’s room for improvement, here.

I could play with some DOM scripting to check the fields and add the notifications, but the point is, I want this to work for users without JavaScript as well (hey, it’s a matter of principal).

I probably have to write a plugin for this to work to check the required fields with PHP. Any pointers?

 Signature 

Low: the Pro Network member who brought you the File Manager Module, Yearly Archives Plugin, Find & Replace Plugin, Akismet Combo, and more…

Profile
 
 
Posted: 09 May 2006 01:41 AM   [ Ignore ]   [ # 1 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  371
Joined  10-18-2004

*kchk* please acknowlegde, over *kchk*

 Signature 

Low: the Pro Network member who brought you the File Manager Module, Yearly Archives Plugin, Find & Replace Plugin, Akismet Combo, and more…

Profile
 
 
Posted: 09 May 2006 07:43 AM   [ Ignore ]   [ # 2 ]  
Moderator
Avatar
RankRankRankRankRankRankRank
Total Posts:  23521
Joined  05-20-2002

JS is the way I’d have gone, because otherwise you’re right- it requires a hack/plugin/extension.  The main file you’ll need to look at is system/modules/mod.comment.php- and you can probably manage this with an extension.  Though I won’t swear to it.

 Signature 

AKA rob1

Help Request TipsPro Network

Profile
 
 
Posted: 11 May 2006 07:31 AM   [ Ignore ]   [ # 3 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  371
Joined  10-18-2004

Right. So I built this quick plugin, and it seems to work. Comment Form Plus is a replacement for the {exp:comment:form} tag (but without the preview option for now…) and can be used like this:

{exp:commentform_plus weblog="my_weblog" required="name|email|comment|spamguard"}
  
<fieldset>
    <
legend>Add a comment</legend>

      <
p><label for="name">Name *{if no_name} <span class="alert">Please fill in your name</span>{/if}</label>
      <
input type="text" name="name" id="email" value="{name}" /></p>

      <
p><label for="email">Email *{if no_email} <span class="alert">Please enter a valid email address</span>{/if}</label>
      <
input type="text" name="email" id="email" value="{email}" /></p>

      <
p><label for="url">URL</label>
      <
input type="text" name="url" id="url" value="{url}" /></p>

      <
p><label for="comment">Comment *{if no_comment} <span class="alert">What? No comment?</span>{/if}</label>
      <
textarea name="comment" id="comment" cols="25" rows="5">{comment}</textarea></p>

      <
p><input type="checkbox" name="notify_me" id="notify_me" value="yes" {notify_me} />
      <
label for="notify_me">Notify me</label></p>

      <
p><input type="checkbox" name="spamguard" id="spamguard" value="yes" />
      <
label for="spamguard">This is not spam *{if no_spamguard} <span class="alert">Tick this box, please</span>{/if}</label></p>

      <
p><input type="submit" name="submit" value="Submit" /></p>

  </
fieldset>
{/exp:commentform_plus}

If someone forgets to fill in one of the required fields, the form is shown again, with the {if no_thingie} conditionals properly parsed. When everything is filled in correctly, the form is submitted and the comment will be added. I’ve attached the plugin if anyone else is interested.

File Attachments
pi.commentform_plus.php.txt  (File Size: 5KB - Downloads: 130)
 Signature 

Low: the Pro Network member who brought you the File Manager Module, Yearly Archives Plugin, Find & Replace Plugin, Akismet Combo, and more…

Profile
 
 
Posted: 11 May 2006 07:35 AM   [ Ignore ]   [ # 4 ]  
Moderator
Avatar
RankRankRankRankRankRankRank
Total Posts:  23521
Joined  05-20-2002

Sweet- and thanks for sharing it.  I’m actually going to move this over to the plugin forum.  It will be a lot easy for folks to find as they search that forum in the future.

 Signature 

AKA rob1

Help Request TipsPro Network

Profile
 
 
Posted: 12 February 2007 11:27 AM   [ Ignore ]   [ # 5 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1726
Joined  03-26-2006

Thanks, Low, I just put this plugin to use today. Works great. Thanks for sharing.

 Signature 

ryan masuga
—————
Masuga Design | Member, EE Pro Network
My EE Add-Ons | {devot:ee}
Twitter: masuga | masugadesign | devot_ee

Profile
 
 
   
 
 
‹‹ Plugin: tag_limit      Is filter_html dead? ››
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1149, on July 16, 2007 09:33 AM
Total Registered Members: 64878 Total Logged-in Users: 74
Total Topics: 81804 Total Anonymous Users: 42
Total Replies: 439749 Total Guests: 307
Total Posts: 521553    
Members ( View Memberlist )
Newest Members:  pticketdxrsmdanbilly8hrkiliwysso50kexpressoKlaasdarrenstylestravelerjcaton