How do I pass a variable to a form?

johnnie 27 Aug, 2007
I have created an enquiry form with Chrono and it works beautifully. Great component!

But I want now want to put the link to my enquiry form at the bottom of another component page and be able to pass some variable data from the original page to the Chrono Enquiry form page
(like a reference number) - so they "pre-fill" some of the form fields.

Have searched around the forum but couldn't seem to find this technique. I'd be really grateful for some pointers.

many thanks
Johnnie<br><br>Post edited by: johnnie, at: 2007/08/26 23:56
GreyHead 27 Aug, 2007
Hi Johnnie,

You can put info into the form link by adding get variables to it - but could be messy with Joomla URLs. Probably better to create a little form with just hidden fields and a submit button, the values of the hidden fields will then be available from the $_POST array.

Let us know if you need more detail.

Bob
johnnie 27 Aug, 2007
Hi Bob

Thanks for v.quick and helpful reply.

Making the link to the main form a submit button is a really neat solution. Should be within my skills to put that together I hope :-) I'll have a go at that and report back on my sucess

thanks again, Johnnie
johnnie 03 Sep, 2007
After a few evenings at this..success!! Here's what worked for me.

In my first page I have a variable "name" that I want to past to my Chronoform. This code displays an image as a submit form with my variable(s) as hidden fields:



<form action="http://www.*********/index.php?option=com_chronocontact&chronoformname=Job_Application" method="post">
<input type="hidden" name="jobtitle" value="<?php echo $p->name;?>">
<input type="hidden" name="jobref" value="xyz">

<input type="image" src="/images/applynow.jpg" border="0" name="submit" alt="Click here & apply for this job now" title="Click here & apply for this job now">
<img alt="" border="0">
</form>


The key line above is:

<input type="hidden" name="jobtitle" value="<?php echo $p->name;?>">



Then within the HTML of my Chronoform, this Post command picks up the hidden field from the above...


<?php 
$jobtitle = $_POST['jobtitle']; 
echo $jobtitle;
?>



...and I've cracked it. I am soooo pleased! There are probably more elegant ways of doing this. But it works for me.

I'm a complete novice at this stuff so MUCH thanks to Bob for nudging me in the right direction (and not giving me the full solution) so I could learn something😉


Johnnie<br><br>Post edited by: johnnie, at: 2007/09/03 00:37
GreyHead 03 Sep, 2007
Hi Johnnie,

Well done and glad to be of help.

I'm guessing that you've assigned $p to the $-POST array somewhere in your code?

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