将变量从K2模板传递到RSForm';s字段的默认值


Passing a variable from a K2 template to a RSForm's field default value

我有一个变量

$price = $this->item->extraFields->price->value;

在item.php中,它是Joomla页面详细信息模板。在同一个模板中,我使用RSForm组件加载了一个表单,所以它只是{rsform8}。在表单中,可以为其字段设置默认值。

我想将其中一个字段的默认值设置为$price,这只是一个整数。所以我遵循了这个教程http://www.rsjoomla.com/support/documentation/view-article/369-get-the-page-title.html

还有这个http://www.rsjoomla.com/support/documentation/view-article/77-display-php-variables-by-default-when-form-is-shown.html(相同的+SQL变体)。

然而,每当我尝试将默认值放在那里时,我都不会成功。到目前为止,我已经在网上找了三个小时了,但我似乎无法做到我需要的。

因此,在绝望中,我尝试了不同的方法将变量插入如下形式。。。

//<code>
return $price;    
//</code>
//<code>
$p = $price,
return $p;    
//</code>
//<code>
echo $price;    
//</code>
//<code>
print $price;    
//</code>
//<code>
$price;    
//</code>

当然,它们都不起作用。然而,这个有效:

//<code>
$price = 10;
return $price;    
//</code>

我认为问题是页面的模板(item.php)在某种程度上与RSForm表单模板分离,但我真的不知道。

你知道如何解决这个问题吗?我要尝试的另一件事是通过JavaScript在那里添加变量,但我不太喜欢它,因为人们可以关闭JS(无论如何都必须填充字段),我仍然不能确定这是否可能。

当我解决这个问题时,我忘记了回答我的问题,所以现在是,有点新——使用javascript。

// Creating a variable and filling it with the prize
<?php $price = $this->item->extraFields->price->value; ?>

<script type="text/javascript">
// Filling a javascript variable with the php variable
var c1 = "<?php echo $price; ?>";
// Filling my HTML input field in the form with the variable
document.getElementById("price").innerHTML = c1;
</script>

哇,表单中充满了变量。当然,剧本会因为一些条件和接下来的兄弟姐妹而变得复杂,但那是另一个故事。