Forums

passing value form URL to form

jformicola 21 Feb, 2020
Can you please help me. I need to pass a value from a lin to my form and all the examples I'm finding on the forum thus far don't seem to work.

They all seem to involve some variation of this code, which when I add to a custom code block in chronforms6 just seems to throw an error (below)

<?php
if ( !$mainframe->isSite()) {return;}
$var = JRequest::getInt('session', '0', 'get');
?>

ERROR = 0 Call to a member function isSite() on null


Here is an example of the link with the value I want to pass, is that correct? I want that session ID to pass to the form somehow. I need to add that session ID to the name of the signature that is saved once the form submits. Can you please help?

http://XXXXXX/index.php?option=com_content&view=article&id=20&session=544
healyhatman 21 Feb, 2020
{data:name_of_url_parameter}

And you're getting that error because you haven't set $mainframe. You might need to have a closer look at the code you're using to see what you're missing.
GreyHead 22 Feb, 2020
Hi jformicola,

I believe that CF adds the URL data to the form data for you. Please add a Debugger action so you can see what is available in the On Load event.

Bob
jformicola 24 Feb, 2020
Sure enough it was there, thanks. So I didn't need the code to get it there (which is good because I didn't understand healyhatman's comment about the mainframe haha) Thanks guys!

This was the PHP code I used to get the value into the signature if it's helpful for others...

<?php
$data_pieces = explode(",", $this->data[signature8]);
$encoded_image = $data_pieces[1];
$decoded_image = base64_decode($encoded_image);

// set the folder where the images will be saved
$folder = 'images/signatures/';
$path = JPATH_SITE.'/'.$folder;
$url = JURI::root().$folder;
// sets a file name using a date-time prefix to make sure it is unique
$sig_name = $this->data("session").'_'.$this->data("name").'.png';
file_put_contents( $path.$sig_name, $decoded_image);

// add the file info into the form data
return array(
'url' => $url.$sig_name,
'path' => $path.$sig_name
);
?>
This topic is locked and no more replies can be posted.