[SOLVED] Passing variables to a form using url

chozma

Member
Hi all,

I am trying to create a link from a details page to a form page that passes a variable and preloads that variable into a form dropdown box.

After looking through various forum posts it seems that passing the variable through the url is a sensible way to do this. So the page link I want to load is:

Code:
index.php/treatments/form/12

and I am trying to append

Code:
&fm_treatment_animal___Animal=Molly

on the end. But its not working! o_O I'm sure that this is really simple and someone who's done this a million times will spot the stupid mistake instantly... any takers please?!

Thanks as always, hannah
 
The first parameter you append must start with ?
So
...form/12?elemenz1=foo&element2=bar&...

gesendet mit Tapatalk
 
Thanks for that - its always helpful to have a second set of eyes on something especially when you know you are doing something stupid. :oops:

One more question on this.... I was expecting to be able to pass a variable through the url to autopopulate a form field. But I can't get it work, even when I do use a '?' instead of a '&'!

So I have a table called fm_treatment_animal and within that table a databasejoin element called 'Animal'. I thought that

Code:
index.php/animals/form/12?fm_treatment_animal___Animal=Molly

would load up the form with the Animal element prepopulated with the value Molly. I tried also passing a number instead of a string to mirror the option values but I could not get that working either.

Any thoughts? Thanks x
 
If it's a join element, you need to use the value (rather than the label), and append _raw to the element name.

So try fm_treatment_animal___Animal=123

... or whatever the value is.

-- hugh
 
Thanks Hugh. I've been trying with the id number as well still no joy.

I'm sorry but I didn't follow your comment on the append_raw thing - could you explain that a little more please?

I may have totally got this wrong, but literally all I am doing is passing the variable through the url as above and I'm expecting it select the right dropdown option in the form when it loads up. Should I be doing something with the variable in form.php?
 
Ooops, I got my example wrong, should have been:

fm_treatment_animal___Animal_raw=123

Here's a quick screencast of a simple example form, where I have a dropdown (a join element), where the options have values 1, 2 and 3. My element is pie_buy___pie_type_id. So to feed it a value, rather than a label, I append _raw to that.

http://screencast.com/t/spQ4JAgV

In general, when using Fabrik placeholders for any element that has the concept of "value" and "label" (like dropdowns, joins, radiobuttons, etc), appending _raw allows you to get/set the "value" as opposed to the label.

-- hugh
 
Thanks Hugh, that's awesome. I have it working now and appreciate the explainations of using _raw, I'm sure that will come in handy for later.

Much obliged as always! :D
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top