PHP联系表单覆盖字段问题重复值

发布于 2024-08-24 20:39:15 字数 752 浏览 5 评论 0原文

我正在使用 http://phpfmg.sourceforge.net/home.php。我想我应该添加一个焦点效果,这样当我单击字段时,值会自动消失。

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

H I'm using php contact form from http://phpfmg.sourceforge.net/home.php. I thought I'd add an onfocus effect so when i click in the fields the value dissappears automatically.

But when I submit say if haven't filled in my requried fields I get this the values appearing again like
http://s647.photobucket.com/albums/uu199/judibluebottles/YETI%20images/?action=view¤t=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">

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

囚你心 2024-08-31 20:39:15

您需要在表单上使用 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);" ...>

You'll want to use an onsubmit handler on the form that does the same thing the onfocus does: Clears the text out of the box if it's the default text. That way, the fields will be blank when they're submitted.

To do that, I'd put some structure in place to avoid duplicating code. Completely off the cuff:

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 for fields:

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

onsubmit for form:

<form ... onsubmit="formSubmit(this);" ...>
你的笑 2024-08-31 20:39:15

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

如果有人为 pixie cms 制作一个高级插件那就太好了:)

I've given up doing complicated php contact forms unless someone has a miracle one that can do almost anything? For Wordpress contactform 7 is the easiest i've come across.

Would be great is someone makes an advanced plugin for pixie cms :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文