2010-03-12 63 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高级插件:)