Hi there,
I would like to design a ChronoForm with one dropdown field where I'd like to pre-select the right entry according to the URL of the page the form is displayed on.
GreyHead already suggested a great solution whenever the field is a post-fix to the URL, such as in website.com/form.hrml?field=value123 . No need to do anything here ...
What I'm looking for is a little more complex. I'd like to scan the URL for keywords, and the adjust the dropdown accordingly.
I wrote some code for a previous version of CF, and it worked quite well - although I'm not sure as to incorporate it in CF5. It goes like:
Now, what the code does: It scans the URL for keywords, and if found, returns the appropriate value for $topic.
For website.com/carrotsales.html, it would return "vegetable" for $topic.
For website.com/wedontlikenoapples.html, it would return "fruit" for $topic.
I've tried to include the code in the Designer in a custom field, and just made sure I also used "topic" as a field name for the drop-down. Didn't work. Any suggestions on this one?
I would like to design a ChronoForm with one dropdown field where I'd like to pre-select the right entry according to the URL of the page the form is displayed on.
GreyHead already suggested a great solution whenever the field is a post-fix to the URL, such as in website.com/form.hrml?field=value123 . No need to do anything here ...
What I'm looking for is a little more complex. I'd like to scan the URL for keywords, and the adjust the dropdown accordingly.
I wrote some code for a previous version of CF, and it worked quite well - although I'm not sure as to incorporate it in CF5. It goes like:
<?php
$topic = "novalue";
$topiclist = array ("apple", "carrot");
$chose = ''; $counter = 0;
$urli = $_SERVER['REQUEST_URI'];;
foreach ($topiclist AS $check)
{
$counter = 0;
$counter = substr_count($urli,$check);
if ($counter != 0) {$this = $check;}
}
if ($this == "apple") {$topic = "fruit";}
else if ($this == "carrot") {$topic = "vegetable";}
?>
Now, what the code does: It scans the URL for keywords, and if found, returns the appropriate value for $topic.
For website.com/carrotsales.html, it would return "vegetable" for $topic.
For website.com/wedontlikenoapples.html, it would return "fruit" for $topic.
I've tried to include the code in the Designer in a custom field, and just made sure I also used "topic" as a field name for the drop-down. Didn't work. Any suggestions on this one?