我正在构建一个laravel连接mailchimp到联系表单的应用程序。用户必须接受条件,并有可能通过选中复选框来接收时事通讯。现在,当用户同时接受条件和时事通讯时,表单提交成功,但是当用户不选中时事通讯复选框时,表单未提交,我真的不知道为什么。
这里的输入
<input name="conditions" value="1" type="checkbox" class="custom-control-input" id="applyConditions" required>
<input type="checkbox" name="newsletter" class="custom-control-input" id="contactNewsletterSubscribe">
和我的控制器:
class ContactController extends Controller
{
public function store()
{
$validator = Validator::make(request()->all(), [
'email' => ['required', 'email'],
'name' => ['required', 'string'],
'phone' => ['string'],
'subject' => ['required', 'string'],
'message' => ['required', 'string'],
'conditions' => ['accepted', 'boolean'],
]);
if ($validator->fails()) {
return response()
->json($validator->messages(), 400);
}
if (request()->has('newsletter')) {
Newsletter::subscribePending(request()->email);
if (!Newsletter::lastActionSucceeded()) {
return response()
->json($validator->messages(), 400);
}
}
Mail::to('my@mail.com')
->send(new ContactUsMessage([
'email' => request()->email,
'name' => request()->name,
'phone' => request()->phone,
'subject' => request()->subject,
'message' => request()->message,
]));
return response()->json('OK', 200);
}
}
当我同时选中conditions和newsletter复选框时,表单数据返回:
conditions: 1
newsletter: on
当条件被接受但通讯复选框未被选中时,表单数据返回:
conditions: 1
newsletter: undefined
有人能告诉我我做错了什么吗?
慕雪6442864