Forums

Populate Form Field From Querystring or Form Data

noxbane 12 Oct, 2010
So I'm displaying a list of courses. Each course has several dates. Next to each course/date combo is a "register" button. This, when clicked, leads to a simple form built in Chronoforms (NOT a joomla registration form) that gathers their contact info which is then emailed to the site admin.

On this form, I want to prepopulate the Course Name and Course Date fields with the info from the course listing page. The info will be passed either through the Querystring or through form post data. Is this as simple as doing a
<input type="text" name="className" value="<?php echo $_GET["className"]; ?>" /> 

or is there something specific to Chronoforms I need to know?
GreyHead 12 Oct, 2010
Hi noxbane,

That will do the job. The slightly preferred version using Joomla code would be
 <?php
if ( !$mainframe->isSite() ) { return; }
$class_name = JRequest::getString('class_name', 'default_value', 'get');
?>
<input type="text" name="className" value="<?php echo $class_name; ?>" /> 
This adds some data filtering to the input to protect against malicious URLs.

You might also just pass a class id in the URL and look up all the class details from a database table in the Form HTML.

Bob
noxbane 12 Oct, 2010
Thanks Greyhead! Great and fast help as always.

What is the best place for me to learn more about Joomla classes and other code that is available to me? Is http://docs.joomla.org the best place? It seems to do a good job of outlining everything, but I didnt know if there was another good resource that I was not aware of. I have years of ASP programming experience but little PHP/Joomla experience
GreyHead 15 Oct, 2010
Hi noxbane,

Sorry, I missed a few posts including this one.

Yes the Joomla docs are the best place but they are patchy. The api docs at api.Joomla!.org are complete but you need to have an idea of what you are looking for and read the PHP in some cases.

I usually try those two first, then Google for the classname + Joomla. That may find forum posts or other tutorials that are more useful.

If all else fails I'll dig in the code and sometimes add debug outputs to see exactly what is happening.

Bob
This topic is locked and no more replies can be posted.