PDA

View Full Version : validation on forms & making a hidden field auto increment


wilfy
01-21-2007, 03:46 PM
Hi guys

I couldn't get mosforms 0.4b to validate fields and am having problems with fabrik too just wondering if anybody else has had any probs.
basically if try to validate a field to be not null it works but will not come up with an error message. it just reloads the form. I am using the fabrik module to put it on the frontpage of our joomla instance http://www.1stuphillscouts.co.uk/funday2007/

was also wondering whether there was anyway of auto generating a reference number that auto increments and i could include this inthe receipt email. we are basically using fabrik as a way of collating interest in an event we are running. i tried using {fabrik_internal_id} to use the primary key to no avail :(

all help gladly appreciated

Wilfy

lars_stecken
01-21-2007, 04:22 PM
Hi,
I am having the same problems using validation. I think it is impossible for this to work since there is only the rule_lable stored in table _fabrik_validation_rules but no rule_expression itself. I cannot add a regular expression by the normal admin interface - saving the rule doesn't seem to work.
Also, editing the db_table directly didn't work.
If I select 'not empty' as validation rule this is what I get http://www.moderndance-berlin.de/index.php?option=com_fabrik&Itemid=67

I think this is a great peace of software even without documentation. Hope you can fix this validation bug.

Greets, Lars

rob
01-22-2007, 01:09 PM
Hey guys

OK this is a bug regarding creating new validation rules. To fix it go to line 467 of administrator/components/com_fabrik/admin.fabrik.php

find this code:


case "saveValidationRule":
case "applyValidationRule":


and replace with


case "saveValidationRule":
case "applyValidationRule":
saveValidationRule();


Lars - could you tell me what access rights you have set up for the table whose form you posted in your link please?
I think your issue is that users arent allowed to edit a record, hence when the validation fails and you are returned to the form, Fabrik blocks you from seeing it.
If that is the case then I will fix that for the next release.

Wilfy - do you get the error messages showing when you use the form as a component, rather than displaying it as a module?
I see your point about the internal id. I've fixed this for the next release of Fabrik, its a bit complicated to implement simply by asking you to edit files. The release should happen pretty soon, as it will simply be addressing some bugs and issues that have come up since the 1.0 release.

Cheers
Rob

wilfy
01-22-2007, 02:43 PM
Thanks Rob

Have checked out my form in component mode and it will show the error message at the top, but not the message for each element... thank you so much for your help. it really is much appreciated. you do an amazing job :)

I understand with the internal id thing that it probably was a bit more technical, thanks for looking into it though :)

Wilfy

lars_stecken
01-22-2007, 07:40 PM
Hi Rob,

thanks a lot for your help. You were right. Only if I change all permissions back to "public" the form gets redirected to itself and shows the error message.
One more question: what would be the right synthax for a validation rule? Like this: /w+/ ?

Thanks a bunch, Stefan (my real name ;-)

freeuser
01-24-2007, 10:10 AM
HI Stephan ;)

you would need to enter


w+


I think that would match any string as long as it contained at least one "w" (I'm not too hot on regular expressions) - is that the case?

Cheers

rob
01-24-2007, 10:11 AM
woops - posted the last post whilst logged in as a test user - sorry !

lars_stecken
01-24-2007, 10:34 AM
Hi Rob, yes that's right. RegEx is a science for itself, but once you get into it well worth the struggle. It solves tons of problems in one line where before you had to construct complicated loops.
So the validation expression gets validatet in preg_match()? Is that right? Of course I could also search the source code :-)

Thanks again and greets,
Stefan

rob
01-24-2007, 05:54 PM
yes its preg_match :D

Rob

lars_stecken
01-29-2007, 09:45 PM
Hi Rob,
I just tried a regex on for Email-validation which I have often used before. But for one it doesn't work an two you can't edit it. May be some escaping problem when you save the expression in the db?

^((\"[^\"\f\n\r\t\v\b]+\")|([\w\!\#\$\%\&\'\*\+\-\~\/\^\`\|\{\}]+(\.[\w\!\#\$\%\&\'\*\+\-\~\/\^\`\|\{\}]+)*))@((\[(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))\])|(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))|((([A-Za-z0-9\-])+\.)+[A-Za-z\-]+))$

Would be great if you could check on that.

Cheerio,
Stefan

rob
01-30-2007, 08:15 AM
Hi

A couple of issues that had to be fixed here.
First of all in /administrator/components/com_fabrik/views/validationrule/tmpl/default, line 30 replace


<td><input class="inputbox" type="text" name="validation_rule_expression" size="75" value="<?php echo $row->validation_rule_expression; ?>" /></td>


with



<td><input class="inputbox" type="text" name="validation_rule_expression" size="75" value="<?php echo htmlentities($row->validation_rule_expression); ?>" /></td>


Then due to the length of your expression, you need to change table "jos_fabrik_validation_rules" field "validation_rule_expression" type from varchar 255 to text.

However, even after all that your expression always causes my test email addresses to fail.
I took a look at my code and its infact using ereg rather than preg to perform the expression, might that be the problem?

lars_stecken
01-30-2007, 08:28 AM
Hey Rob, thanks for the fast service!
Indeed I am using preg with this expression, but I don't see why it shouldn't work with ereg. Got to check that out, but won't happen so soon (I am an "after-work-programmer" ::))

Anyway, think it would be very cool to have a textarea to post your regex in instead of a text field. Makes it easier to spot flaws and long expressions are also very common.

I'll get back to you on the ereg/preg question.

Greets, Stefan

rob
01-30-2007, 09:54 AM
hi, I've change the field to a text area for the next release

Cheers for the feedback

lars_stecken
01-30-2007, 07:36 PM
Hi Rob,
you were right - it doesn't work with ereg(). Here's one explanation I found on php.net

A common mistake seems to be trying to escape characters within a bracket
expression. Unlike the preg functions, backslash is always taken literally
within a bracket expression using the ereg functions. See
http://php.planetmirror.com/manual/en/function.eregi.php#57824
for more details.

I wonder if you should switch to preg since it's supposed to be a tad faster than ereg. If you don't it would probably be a good thing to give the user a little hint which valaidation function you use. Otherwise it could potentially drive you nuts when you can't find out what's wrong.

Greets from Bavaria,
Stefan

rob
02-01-2007, 09:10 AM
Hi

Switching to preg would mess up peoples current validation rules, but you're right about providing a hint. I've added that for the next release

Cheers
Rob