PHP联系表单覆盖字段发出重复值

时间:2010-03-12 09:49:26

标签: forms field contact repeat

我正在使用http://phpfmg.sourceforge.net/home.php的php联系表单。我以为我会添加一个onfocus效果,所以当我点击字段时,值会自动消失。

但是当我提交时说如果没有填写我需要的字段,我会得到这个值再次出现 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">

2 个答案:

答案 0 :(得分: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);" ...>

答案 1 :(得分:0)

我已经放弃了复杂的php联系表单,除非有人有一个几乎可以做任何事情的奇迹吗?对于Wordpress,contactform 7是我遇到过的最简单的。

如果有人为pixie cms制作高级插件,那将会很棒:)