OJS OCS OMP OHS

You are viewing the PKP Support Forum | PKP Home Wiki



FormValidatorArrayCustom

OJS development discussion, enhancement requests, third-party patches and plug-ins.

Moderators: jmacgreg, btbell, michael, bdgregg, barbarah, asmecher

Forum rules
Developer Resources:

Documentation: The OJS Technical Reference and the OJS API Reference are both available from the OJS Documentation page.

Git: You can access our public Git Repository here. Comprehensive Git usage instructions are available on the wiki.

Bugzilla: You can access our Bugzilla report tracker here.

Search: You can use our Google Custom Search to search across our main website, the support forum, and Bugzilla.

Questions and discussion are welcome, but if you have a workflow or usability question you should probably post to the OJS Editorial Support and Discussion subforum; if you have a technical support question, try the OJS Technical Support subforum.

FormValidatorArrayCustom

Postby osborne » Sun Nov 08, 2009 7:26 pm

I have a form in which the user will enter the details of several items, each of which has the same set of fields. For item1, item2, ... say they will enter a name and a number. I'm getting the items in an array. Thus the fields have labels like
{fieldLabel name="items[$itemIndex][number]" key="form.number"}
{fieldLabel name="items[$itemIndex][name]" key="form.name"}
and the textFields include
name="items[{$itemIndex}][number]"
namer="items[{$itemIndex}][name]"

I want to report an error when for one or more items the user enters a name but not a number, or a number but not a name in a field. If for each item the user enters no name or number, or a name and a number, the form is valid.

Is FormValidatorArrayCustom flexible enough to cover this case, and highlight the fields in the items that are erroneous? It seems that one would need to use the additional argument variables, but I don't see how to make them fit this case.
osborne
 
Posts: 77
Joined: Mon Jun 07, 2004 1:24 pm
Location: Toronto, Canada

Re: FormValidatorArrayCustom

Postby mcrider » Wed Nov 11, 2009 11:20 am

Hi Martin,

Its hard to give you advice without a concrete example; But the FormValidatorCustom sounds like what you should be using--Its pretty powerful, though can be confusing to write rules for (But you can grep the code for 'FormValidatorCustom' to get plenty of exmaples). Of course, you have to write a Form Class to handle your form and instantiate/handle the Form in the appropriate handler class. Let us know if you still need help on this...

Cheers,
Matt
mcrider
 
Posts: 952
Joined: Mon May 05, 2008 10:29 am
Location: Vancouver, BC

Re: FormValidatorArrayCustom

Postby osborne » Thu Nov 12, 2009 6:59 pm

Thanks, Matt. I know FormValidatorCustom pretty well---I've used it a lot---and I don't think it can do what I want. I'm not sure about FormValidatorArrayCustom. The versions of OJS that I have don't include it---I just added it from your CVS---so I can't easily grep to see how it's used. (I found an instance of its use, but that didn't answer my question. I thought Google should have gone through your CVS, but it doesn't seem that it has.)

I have a form like this:

Item 1
Name:
Number:

Item 2
Name:
Number:

Item 3
Name:
Number:

and so on. I'm collecting the user input in arrays. The input is valid if, for each item, *either* there is both a name and a number *or* there is neither a name nor a number. It's easy to use FormValidatorCustom to report an error under the right circumstances, but I don't see how to get the offending fields to be highlighted (i.e. the name field for an item where the user has entered only a number, and the number field for an item where the user has entered only a name, but no other fields). Seems like FormValidatorArrayCustom might be able to do it, but so far I haven't been able to find how. The problem is that while it can work with all the name fields, or all the number fields, I don't see how to get it to work with both.
osborne
 
Posts: 77
Joined: Mon Jun 07, 2004 1:24 pm
Location: Toronto, Canada

Re: FormValidatorArrayCustom

Postby mcrider » Fri Nov 13, 2009 11:53 am

Hi again Martin,

I'm not sure which FormValidator would better server (most likely FormValidatorArrayCustom), but I'd recommend adding a FormValidator handler for each pair of form elements you have. For example, one instance of FormValidatorArrayCustom would only consider item 1 and would return true if both fields are filled out or neither field is filled out. Trying to handle all of the items at once seems just a little too complicated, not necessarily for tracking errors but for reporting them to the right place as you've mentioned.

Cheers,
Matt
mcrider
 
Posts: 952
Joined: Mon May 05, 2008 10:29 am
Location: Vancouver, BC


Return to OJS Development

Who is online

Users browsing this forum: No registered users and 1 guest

cron