How to make category required on SAEF? 
Posted: 15 November 2007 05:14 PM   [ Ignore ]  
Grad Student
Avatar
Rank
Total Posts:  44
Joined  2007-11-05

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 10:42 PM   [ Ignore ]   [ # 1 ]  
Moderator
Avatar
RankRankRankRankRankRank
Total Posts:  9885
Joined  2002-04-29

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 

Quick Reference - EE Trial Options - EE Wiki - Docs for updating a build

Profile
 
 
Posted: 26 November 2007 05:32 PM   [ Ignore ]   [ # 2 ]  
Grad Student
Avatar
Rank
Total Posts:  44
Joined  2007-11-05

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 08:37 AM   [ Ignore ]   [ # 3 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1285
Joined  2006-08-02
Sue Crocker - 15 November 2007 10: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 05: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 <em>if</em> javascript is turned off by the user, FreeForm’s built in validation handling should kick in. smile

 Signature 

Deron Sizemore
Random Jabber - My Blog
Sizcons - My Icon Set
Nice Stylesheet - Fresh CSS Inspiration
Kentucky Golfing - Kentucky’s Online Golf Resource

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

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

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

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 Tips * Pro 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 1149, on July 16, 2007 10:33 AM
Total Registered Members: 58059 Total Logged-in Users: 34
Total Topics: 68029 Total Anonymous Users: 23
Total Replies: 366440 Total Guests: 457
Total Posts: 434469    
Members ( View Memberlist )