How to make category required on SAEF?
Posted: 15 November 2007 04:14 PM   [ Ignore ]  
Lab Assistant
Avatar
RankRank
Total Posts:  121
Joined  11-05-2007

Hopefully this is a simple one…

How do you require someone to select a category on the stand alone entry form?

Here’s that chunk of code from the SAEF:

{category_menu}
<dt{if required} class="required"{/if}><label for="category"><strong>Category:</strong></label></dt>
<
dd>
<
select name="category[]" size="4">
{select_options}
</select>
</
dd>
{/category_menu}

But, currently it is accepting entries w/o categories. I’d like to require a category w/o having to provide a default.

Is this possible?

 Signature 

Looking for EE developers. PM me for details.

Profile
 
 
Posted: 15 November 2007 09:42 PM   [ Ignore ]   [ # 1 ]  
Moderator
Avatar
RankRankRankRankRankRankRank
Total Posts:  20193
Joined  04-29-2002

You’d have to add some sort of code to check for a value for category.

Easy Contact Form Validation is an article about validating a Freeform form. You could try this for the SAEF.

Disclaimer: I have not done this with a SAEF. But I have done it with Freeform several times.

 Signature 

EE 2.01PB - 2.x Bug Tracker | Docs | Upgrade from 1.x to 2.x | Build Update Instructions | 1.6.x Update Info

Most recent 2.x version: Build 20100121
Don’t forget to upgrade MSM and Forum as needed!

Profile
MSG
 
 
Posted: 26 November 2007 04:32 PM   [ Ignore ]   [ # 2 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  121
Joined  11-05-2007

Thanks for the tip. I got validation to work with the SAEF, but it took a bit of work.

The validation code relies on each form field to have a specific CSS class. Since EE auto generates the form’s html, I used jquery to dynamically add the CSS class to each of the form’s input fields. (I suppose I could have fiddled with the EE code to do this, but jquery seemed an easy way to go.)

Unfortunately, jQuery and Prototype don’t play well together out of the box, so I had to use a workaround for that. But, it’s working well now.

Here’s the code that’s different from the example above. Add all of this below your EE form (and of course, declare your jQuery reference in the page’s header.

// Jump through hoops to get prototype and jquery to play nicely
    // http://wordpress.org/support/topic/141394?replies=7
    
$j=jQuery.noConflict();
    
    
// Use jQuery via $j(...)
    
$j(document).ready(function(){
        $j
("#field_id_38").addClass("required");
        
$j("#field_id_40").addClass("required");
        
$j("#field_id_39").addClass("notrequired");
        
$j("#category").addClass("notrequired");
    
});

    var
valid = new Validation('entryform', {immediate : true}, {stopOnFirst : false});

My only complaint is that this validation is all being done in javascript which can be turned off by the user. Perhaps an EE feature request could be created to add a checkbox or EE parameter that makes categories required?

 Signature 

Looking for EE developers. PM me for details.

Profile
 
 
Posted: 27 November 2007 07:37 AM   [ Ignore ]   [ # 3 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1917
Joined  08-02-2006
Sue Crocker - 15 November 2007 09:42 PM

You’d have to add some sort of code to check for a value for category.

Easy Contact Form Validation is an article about validating a Freeform form. You could try this for the SAEF.

Disclaimer: I have not done this with a SAEF. But I have done it with Freeform several times.


Thanks for that recommendation on my article Sue! Glad you’ve found some use for it. smile

siffring - 26 November 2007 04:32 PM

My only complaint is that this validation is all being done in javascript which can be turned off by the user. Perhaps an EE feature request could be created to add a checkbox or EE parameter that makes categories required?

Yeah, that’s one thing I never thought about for the SAEF. I’ve never needed to use a SAEF though, so I guess that’s why I didn’t think about it. wink With FreeForm thought, it’s very easy to mark fields required, so if javascript is turned off by the user, FreeForm’s built in validation handling should kick in. smile

 Signature 

Deron Sizemore
==========
Random Jabber | LogoGala | Kentucky Golfing
Twitter: Deron Sizemore | LogoGala

Profile
 
 
Posted: 01 April 2008 12:30 AM   [ Ignore ]   [ # 4 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  276
Joined  06-24-2007

Be sure to check out LiveValidation - its a really nice prepackaged javascript validation script and is easy to implement on any form.  http://www.livevalidation.com

 Signature 

Chad Crowell | Encaffeinated, Inc. | Formerly Web Inception | @chadcrowell | @encaffeinated

Profile
 
 
Posted: 01 April 2008 09:16 AM   [ Ignore ]   [ # 5 ]  
Moderator
Avatar
RankRankRankRankRankRankRank
Total Posts:  25420
Joined  05-20-2002

An extension is also an option if you don’t want to go the js route.  But yep- lots of approaches.  Thanks for sharing how you squared away the class issue!

 Signature 

AKA rob1

Help Request TipsPro Network

Profile
 
 
   
 
 
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 1743, on December 02, 2009 02:47 PM
Total Registered Members: 114982 Total Logged-in Users: 85
Total Topics: 122429 Total Anonymous Users: 40
Total Replies: 647263 Total Guests: 446
Total Posts: 769692    
Members ( View Memberlist )