2010-03-12 117 views
0

H我使用的是http://phpfmg.sourceforge.net/home.php的php聯繫表格。我想我會添加一個onfocus效果,所以當我點擊字段中的值會自動消失。PHP聯繫表格覆蓋字段問題重複值

但是,當我提出說,如果沒有填寫在我requried領域我得到這個值再次出現像 http://s647.photobucket.com/albums/uu199/judibluebottles/YETI%20images/?action=view&current=form_issue.jpg http://i647.photobucket.com/albums/uu199/judibluebottles/YETI%20images/form_issue.jpg?t=1268387405

<input type="text" class="text_box" onfocus="if(this.value=='Telephone')this.value='';" value="TelephoneTelephone" id="field_5" name="field_5"> 

回答

0

你會想,做的表格上使用onsubmit處理器onfocus也會這樣做:如果它是默認文本,則將文本從框中清除。這樣,這些字段在提交時將爲空白。

要做到這一點,我會放置一些結構以避免重複代碼。 完全即興:

var Placeholders = { 
    "field_5": "Telephone", 
    // ...and the other fields... 
}; 

function clearFieldPlaceholder(field) { 
    var placeholder; 

    placeholder = Placeholders[field.name]; 
    if (placeholder && field.value == placeholder) { 
     field.value = ""; 
    } 
} 

function formSubmit(form) { 
    var index; 

    for (index = 0; index < form.elements.length; ++index) { 
     // You may want to filter here a bit, e.g., check if it's 
     // a text field 
     clearPlaceholder(form.elements[index]); 
    } 
} 

onfocus的領域:

<input ... onfocus="clearPlaceholder(this);" ...> 

onsubmit的形式:

<form ... onsubmit="formSubmit(this);" ...> 
+0

WOw謝謝T我在哪裏把這個代碼?我有兩個文件form.php和form.lib.php文件 – 2010-03-12 10:10:33

+0

在頁面上的'script'標籤中,例如:''或者鏈接在單獨的文件中到頁面通過'' – 2010-03-12 10:12:56

+0

這是我的網站上的一個例子http://artygirl.co.uk/form.html php看起來很複雜嗎? – 2010-03-12 10:15:57

0

我已經放棄了做複雜的PHP接觸形式,除非有一個人奇蹟,幾乎可以做任何事情?對於Wordpress,contactform 7是我遇到的最簡單的。

將是偉大的是有人爲精靈cms高級插件:)