问题描述
我为需要电子邮件地址和姓氏的系统创建一个基本的订阅表单(SugarCRM以防任何人感兴趣)。
我需要填充 的姓氏输入值(任何内容,无关紧要)仅限,如果访问者没有放入自己的姓氏。
由于订阅操作是托管的(邮件黑猩猩),我无权访问它进行预验证,除非在传递之前发生这种情况。我正在涉足更深入的PHP领域,而不是我自己熟悉的!这可能与 jQuery
?
因此,基本上我通过填写值 如果没有值,请检查表单提交中的姓氏,将foo
in:
$('#formId')。submit(function ){//将提交处理程序附加到表单
var $ lastName = $('#lastName'); //获取姓氏元素
if(!$ lastName.val())/ / $如果它没有值
$ lastName.val('foo'); //把foo作为一个值
});
您应该替换 formId
和 lastName
到表单和姓氏元素的实际ID。
I'm creating a basic subscribe form for a system that requires both email address and last name (SugarCRM in case anyone is interested).
I need to populate the last name input value with something (anything, it doesn't matter) only if the visitor doesn't put their own last name in.
As the subscribe action is hosted (Mail Chimp) I don't have access to it to pre-validate, unless this can happen before it's passed on. I'm wading into deeper PHP waters than I'm comfortable with! Is this possible with jQuery
?
So basically I'm getting around the required last name by filling the value with something.
Check the lastname on submit of the form, if it doesn't have value, put "foo"
in it:
$('#formId').submit(function() { // attach submit handler to the form.
var $lastName = $('#lastName'); // get the last name element.
if (!$lastName.val()) // if it doesn't have value.
$lastName.val('foo'); // put foo as a value.
});
You should replace formId
and lastName
to the actual ids of the form and last name element.
这篇关于HTML表单 - 如果没有输入任何内容,请用值填充输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!