Multiple Models in Form Validation. Skip on Empty

Hey guys.

I’m sure this has been mentioned before but I can’t seem to find a post about it so I thought I’d just ask.

I have a page that has 10 of the same models. This is a webpage to submit referrals.

I have no problem showing the 10 models and in the controller parsing through the data. However what I’d like to do is just have the model validation ignore any of the models that are completely blank.

Example

Rules:

Name - required

Email Address - Email

Phone Number - Custom validation

If all of them are blank then don’t bother run the validation and also don’t bother trying to save them. This will allow the user to supply less than 10 referrals at a time without my page lighting up like a Christmas tree with errors when there are validation problems within the referrals they are trying to submit.

I hope I was able to explain that clearly.

Any help would be great… even a point in the right direction on this.

Thanks!

Why not just start out with one row?

And then let the user add a row by means of jQuery?

And another… and another.

When the user has added the max number (10?) he/she can submit it.

jQuery has a plugin called Appendo IIRC which can help you.

And I believe I saw a Yii extension for it, but I could be wrong.

Thanks for the idea jacmoe.

There are a couple of reasons why I may not pursue that route. One is that it’ll make the page design look very empty. I know it’s a minor thing and the page could be filled with other junk but I’d like to make this as simple as possible. It’s thought enough trying to get a user to fill out a referral form without it being the slightest bit confusing.

The second reason goes along the lines of simplicity as well. I believe the "add another" button would be great in a scenario where the user will use the form again and again. But for a one time user it must be something even a computer illiterate could figure out in 0.5 seconds.

I will however likely use that idea on another page I’ll be building.

Alright, then.

How about this:

Attach a piece of jQuery to the on click event of the submit button.

It sends an array of all entries not empty.

That would probably be your best option. :)