問題描述
我有一個(gè) post php 表單和一組輸入:
I have a post php form and a set of inputs:
- 你的名字
- 您的姓氏
- 我的名字
每個(gè)輸入看起來都一樣,只是名稱發(fā)生了變化:
Every input looks the same, only the names change:
<input type="text" name="your_name" value="<?php echo get_option('your_name'); ?>" />
當(dāng) value= 不可用時(shí)如何設(shè)置默認(rèn)值?
How to set default values when value= is not available?
好吧,通常我會這樣做:
Ok, so, normally I'd do something like:
<input type="text" name="your_name" value="Mike" />
但在這種情況下,我有一個(gè) PHP 腳本,它獲取輸入數(shù)據(jù)并使用 value="<?php echo get_option('your_name'); ?>"
顯示它.所以我不知道如何強(qiáng)制我的表單在我的輸入中顯示Mike".
But in this case I have a PHP script that grabs inputs data and displays it using value="<?php echo get_option('your_name'); ?>"
. So I have no idea how to force my form to display "Mike" in my input.
推薦答案
需要先檢查 get_option 的返回值,如果默認(rèn)值不可用則替換
You need to check the return of get_option first, and substitute something if a default is not available
<?php
$default = get_option('your_name');
if( $default == "")
{
$default = <whatever your default value is>;
}
?>
<input type="text" name="your_name" value="<?php echo $default; ?>" />
如果默認(rèn)值不可用,請更改 get_option 以返回空字符串(或其他內(nèi)容).
Change get_option to return an empty string (or something else) if the default is not available.
這篇關(guān)于HTML/PHP - 默認(rèn)輸入值的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!