【问题标题】:Passing a variable from a K2 template to a RSForm's field default value将变量从 K2 模板传递到 RSForm 的字段默认值
【发布时间】:2013-11-22 11:26:36
【问题描述】:

我有一个变量

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

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

我想将其中一个字段的默认值设置为 $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 变体)。

但是,每当我尝试将默认值放在那里时,我都没有成功。到目前为止,我已经在互联网上四处寻找了 3 个小时,但我似乎无法做我需要的事情。

所以在我绝望的情况下,我尝试了不同的方法将变量插入到表单中,如下所示...

//<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(无论如何都必须填写该字段),我仍然不能确定也有可能。

【问题讨论】:

    标签: php joomla2.5


    【解决方案1】:

    当我解决这个问题时,我忘记回答我的问题,所以这里是,最近 - 使用 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>
    

    哇,表格中充满了变量。当然,脚本会因为某些条件和下一个兄弟姐妹而变得复杂,但那是另一回事了。

    【讨论】:

      猜你喜欢
      • 2014-10-23
      • 2016-10-10
      • 2021-01-15
      • 2019-09-12
      • 2013-12-16
      • 1970-01-01
      • 2012-02-02
      • 1970-01-01
      • 2016-04-26
      相关资源
      最近更新 更多