Forums

Changing pre-selected Dropdown field according to URL [CF6]

OlliMuc 06 May, 2018
Dear Community,

I had a code on CF5 that worked beautifully and changed the pre-selected dropdown field in a form according to the URL the form was display on.

As an example:
<?php
$topics = array ("apple", "banana", "orange");
$chose = ''; $counter = 0;
$urli = $_SERVER['REQUEST_URI'];;

foreach ($topics AS $checkit)
{
$counter = 0;
$counter = substr_count($urli,$checkit);
if ($counter != 0) {$pick = $;}
}
if ($wahl == "apple") {$preselect = "fruitlover";}
else if ($pick == "orange") {$preselect = "vitamin-c";}
else if ($pick == "banana") {$preselect = "lovesyellow";}


$form->data['preselect'] = $preselect;
?>

This worked brillant, if the URL was website.com/our-apples, the form dropdown called "preselect" would display "fruitlover".

In CF6, this doesn't work anymore. Surely it just needs some tinkering, but I'm somewhat lost as to WHERE to apply the correct changes. Any suggestions ... ??
GreyHead 06 May, 2018
Answer
1 Likes
Hi OlliMuc,

The $form->data line no longer works in CFv6 - Please see this FAQ

Bob
OlliMuc 06 May, 2018
Thanks for pointing me in the right direction, Bob! It was you who pointed me to this functionality in the first place quite a while back ...
For anyone else Googling how to solve this, or looking how to pre-populate fields in Chronoforms ....

Removing
$form->data['preselect'] = $preselect;
... and replacing it with ...
$this->data("preselect", $preselect, true);
... did the trick. The form now pre-choses a fitting dropdown-field, according to (a part) of the URL it's embedded on.
This topic is locked and no more replies can be posted.