Form validation component for site

286 views
Skip to first unread message

Liam

unread,
Feb 21, 2012, 6:14:09 AM2/21/12
to Joomla! General Development
Anybody have documentation detailing how to add client/server side
validation on the frontend?

At the moment my component uses a redirect to point back to the form
if input is invalid, however as this is a redirect I can not then
retrive the information that they entered, which means they have to
start over again. I can do this in PHP but want to keep my component
in keeping with the Joomla core code.

Any suggestions would be a great help, I have tried googling but keep
getting documentation for the backend...

Thanks again.

Rouven Weßling

unread,
Feb 21, 2012, 9:11:59 AM2/21/12
to joomla-de...@googlegroups.com
If you use JForm you'll gain server side validation for many fundamental datatypes for free.

Rouven

> --
> You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.
> To post to this group, send an email to joomla-de...@googlegroups.com.
> To unsubscribe from this group, send email to joomla-dev-gene...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/joomla-dev-general?hl=en-GB.
>

JSamir

unread,
Feb 21, 2012, 1:13:02 PM2/21/12
to joomla-de...@googlegroups.com

Liam

unread,
Feb 22, 2012, 7:55:19 AM2/22/12
to Joomla! General Development
Thanks both, so looks like its the same for the frontend as in the
backend.

I will have a read.

Liam

unread,
Feb 22, 2012, 8:18:09 AM2/22/12
to Joomla! General Development
Don't think JForm will work for me will have to code it by hand unless
someone can say yes or no.

Reading the documentation I can not use my function to save the
record, when using JForm? Validation and returning to the form with
the information filled out is done by the builtin function?

Hence in my case where I want my component to update the database and
email a couple of people wouldn't work?

Or is there a way of adding on to the builtin function? So letting
Joomla doing the work for validating the form and creating it, then
once all validated and everything is good, then run my custom function
to do the bits I want?

I am struggling to understand how the process works.

elin

unread,
Feb 22, 2012, 9:45:27 AM2/22/12
to joomla-de...@googlegroups.com

Obviously the CMS couldn't be using JForm all over if it were not possible to save.

If the name of the field (or fields for json strings of fields) matches the database field name it will save in that field.


Elin

Rouven Weßling

unread,
Feb 22, 2012, 5:06:20 PM2/22/12
to joomla-de...@googlegroups.com

On 22.02.2012, at 14:18, Liam wrote:

> Don't think JForm will work for me will have to code it by hand unless
> someone can say yes or no.
>
> Reading the documentation I can not use my function to save the
> record, when using JForm? Validation and returning to the form with
> the information filled out is done by the builtin function?
>
> Hence in my case where I want my component to update the database and
> email a couple of people wouldn't work?
>
> Or is there a way of adding on to the builtin function? So letting
> Joomla doing the work for validating the form and creating it, then
> once all validated and everything is good, then run my custom function
> to do the bits I want?
>
> I am struggling to understand how the process works.

I'd suggest to look a bit more at the MVC classes we have, JControllerForm is very useful. For things like sending E-Mails after save I use the postSaveHook method.

Rouven

Liam

unread,
Feb 23, 2012, 7:02:46 AM2/23/12
to Joomla! General Development
Thanks Rouven, for the postSaveHook, just got learn how to use it! So
I guess you the basic is that you let the JForm pass data and save,
once saved you retrive the data and perform additional functionality?

At the moment my front end is basically leave a comment and add me to
your newsletter, I have now redisgned my form to use JForm and it is
pulling from the XML file absolutely fine. My function at the moment
is very long and using something like postSaveHook would make the code
shorter and neater. I don't want my commenters to sign up for an
account so part of the process is generating a random key to include
in the URL sent to them in an email, when asked to verify their email
is valid, can JForm create a random key for such purpose? Or shall I
create one as I am doing now and update the table row with it after
postsavehook?

I am also interested to see if I can implement this in my backend, my
main form for adding to the database also includes an image upload.
Currently I have a mix of JForm for the data input and a manual image
upload input (coded directly on to the tmpl). I think the image upload
is a problem as I have made a class that resizes the image to a
standard width to stop people uploadoing 5MB photos!
Reply all
Reply to author
Forward
0 new messages