User URL parameters to set default values in form

erike24 15 Mar, 2014
Hi,

I have a form with an email address and some other stuff on it. The customer now would like to launch that form from an application and have some default values populated, so we're thinking of doing it using url parameters.

How should I do this?

I've tried adding a custom code block in onLoad and do something like <?php $form->data["input_email"]="blah" ?> in the code block but that didn't do the trick.

Any ideas would be welcome!

ee
erike24 15 Mar, 2014
Another one answering his own question: it turns out correct spelling helps.

I added a Custom Code activity before the Show HTML in the OnLoad block, with the following contents:

<?php
$form->data['serial_number']=JRequest::getVar('sn');
?>

Mode could be view or controller, both seem to work.
GreyHead 16 Mar, 2014
Hi erike24,

ChronoForms will automatically add any parameters from the URL to the $form->data array (add a Debugger action temporarily to check). If you use the same name in both you don't need the Custom Code. If the names are different then you can do:
<?php
$form->data['serial_number'] = $form->data['sn'];
?>

Bob
erike24 16 Mar, 2014
Hi Bob,

Thanks, I hadn't noticed that before. You're making it too easy :-)

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