The Joomla! Forum ™



Forum rules


Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.



Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Tue Apr 17, 2012 6:47 am 
Joomla! Apprentice
Joomla! Apprentice

Joined: Thu Apr 12, 2012 7:14 am
Posts: 8
I have created a component. In this component I have created the form fields using xml file. In xml file I set the attribute
Code:
required='required'
of a text field and that field become a required field automatically.

But Now I have a component which has created the form in a php file using html input tags. And now I want to make a textfield required in that form so how will I do this? As in the input tag I can't enter the
Code:
required='required'
attribute.

So what should I do with this so that the textbox becomes a required field and without entering some text in that field it should not be submitted.


Top
 Profile  
 
PostPosted: Tue Apr 17, 2012 1:30 pm 
User avatar
Joomla! Virtuoso
Joomla! Virtuoso

Joined: Thu Feb 15, 2007 5:48 am
Posts: 3344
Location: Sydney, Australia
You can add a javascript script to the page and associate it with the submit button of the form so that the script is run on the 'onclick' event. If the mandatory textfield is blank, a warning can be displayed and the execution then stops. If everything is all right, the script will submit the form.

On the other hand, the component will also have to check that the mandatory field has been filled in and display a warning if that is not the case. The reason why this is necessary: some clever cookie (pun intended) may want to copy the form and post it to your site without running any javascript.

Your component will also need to scrub any data input clean by using the methods in the JRequest class so that your site does not all of a sudden become 0wn3d by script kiddies. The following articles are mandatory reading for anyone publishing their own components and forms:
http://docs.joomla.org/Retrieving_and_F ... st::getVar
http://en.wikipedia.org/wiki/SQL_injection

_________________
toivo
my first programs were assembled and run in 16KB :)
http://archive.computerhistory.org/resources/text/GE/GE.GE-115SystemSoftware.1967.102646096.pdf#zoom=100


Top
 Profile  
 
PostPosted: Tue Apr 24, 2012 6:13 am 
Joomla! Apprentice
Joomla! Apprentice

Joined: Thu Apr 12, 2012 7:14 am
Posts: 8
But How will I add this? As in xml file we just add
Code:
required='required'
and it sets the validation on the field.

If I add a javascript for validation then it would not be the same validation as joomla applies on the fields and I want the same validation on my form fields.


Top
 Profile  
 
PostPosted: Tue Apr 24, 2012 1:40 pm 
User avatar
Joomla! Virtuoso
Joomla! Virtuoso

Joined: Thu Feb 15, 2007 5:48 am
Posts: 3344
Location: Sydney, Australia
If the component you mentioned does not define the form fields in an xml file and use Joomla's validation routines, it is technically possible to use custom javascript, with or without AJAX calls, to validate that mandatory fields have been filled in and also to check dependencies between fields, before the form is submitted. This requires some javascript skills, though.

_________________
toivo
my first programs were assembled and run in 16KB :)
http://archive.computerhistory.org/resources/text/GE/GE.GE-115SystemSoftware.1967.102646096.pdf#zoom=100


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 



Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group