2013-11-22 40 views
0

我有一個變量從K2模板傳遞變量到RSForm的字段默認值

$price = $this->item->extraFields->price->value; 
其中是的Joomla頁詳細信息模板的item.php

。在相同的模板中,我使用RSForm組件加載表單,所以它只是{rsform 8}。在表單中,您可以將默認值設置爲其字段。

我想設置其中一個字段的默認值爲$價格 - 這只是一個整數。所以我按照這個教程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(並且無論如何都必須填充該字段),並且我仍然無法確定這樣做也可能是這樣。

回答

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> 

而哇,表單中充滿了變量。當然,劇本會因一些條件和下一個兄弟姐妹而變得複雜,但那是另一回事。

相關問題