2016-07-06 69 views
-3

我有一個問題,對於系統工作,我需要將PHP變量 (函數prefer)放入HTML表單中的值屬性中,可以嗎?
可能是解決此問題的一些不同方法。
將變量放入值屬性

<input type="hidden" name="sum" value="<?php $payment ?>"> 
<input type="hidden" name="account" value="<?php $acc ?>"> 
<input type="hidden" name="desc" value="<?php $info ?>"> 

回答

5

echo使用設定值:

<input type="hidden" name="sum" value="<?php isset($payment) ? $payment : '' ; ?>"> 
<input type="hidden" name="account" value="<?php isset($acc) ? $acc : '' ; ?>"> 
<input type="hidden" name="desc" value="<?php isset($info) ? $info : '' ; ?>"> 
+3

最佳用於此三元運營商(或某種形式的條件)。這「可能」會拋出未定義的變量通知(在HTML源代碼中)。很難說OP對「真實/完整」代碼有什麼作用。但我同意「回聲」。 –

+0

謝謝,它的工作原理 – wiaim

+1

@ Fred-ii-提到的三元運算符:'.. value =「<?php echo isset($ variable)?$ variable:'';?>」>'。 – FirstOne