ng-model 值在由 php 函数生成时未被捕获
ng-model values not being captured when generated by php function
所以我有一个函数可以在 Laravel.
中生成蜜罐表单字段
问题是当我使用 Angular 提交表单时,javascript object 不包含 my_time 或 my_name 字段。
public function generate(array $honey_name, array $honey_time)
{
$honey_time_encrypted = parent::getEncryptedTime();
// Encrypt the current time
$html = '<div id="' . $honey_name['name'] . '_wrap" style="display:none;">' .
'<input type="text" ' . $this->attributes($honey_name) . ' id="' . $honey_name['name'] . '" />' .
'<input type="text" ' . $this->attributes($honey_time) . ' value="' . $honey_time_encrypted . '" />' .
'</div>';
echo $html;
}
有什么想法吗?
更新:
Blade 模板
<form ng-submit="submitForm(formData)">
<div class="form-group form-group-lg">
{!! Form::text('name', null, ['class' => 'form-control', 'placeholder' => 'Name', 'ng-model' => 'formData.name']) !!}
{!! Honeypot::generate(['name' => 'my_name', 'ng-model' => 'formData.my_name'], ['name' => 'my_time', 'ng-model' => 'formData.my_time']) !!}
</div>
<div class="form-group form-group-lg">
{!! Form::email('email', null, ['class' => 'form-control', 'placeholder' => 'Email', 'ng-model' => 'formData.email']) !!}
</div>
<div class="form-group form-group-lg">
{!! Form::text('subject', null, ['class' => 'form-control', 'placeholder' => 'Subject','ng-model' => 'formData.subject']) !!}
</div>
<div class="form-group">
{!! Form::textarea('message', null, ['class' => 'form-control', 'rows' => '5', 'placeholder' => 'Message', 'ng-model' => 'formData.message']) !!}
</div>
<div class="form-group">
{!! Form::submit('Send', ['class' => 'btn btn-default center-block']) !!}
</div>
</form>
提交的表单数据:
$scope.submitForm = function(formData) {
console.log(formData);
Contact.submit(formData).then(function(results) {
SweetAlert.swal({
title: "Success!",
text: "Thanks for getting in touch! I usually respond within 12 hours.",
type: "success",
});
});
};
// Output of console.log();
Object {name: "Daniel", email: "abc@123.com", subject: "asdsadsafas fasfaf", message: "asjfasf aalhfsfa flaskfh aklsflakf a"}
所以它缺少 my_time
和 my_name
模型,这导致验证失败。
您没有 <form>
元素。
这样试试:
$html = '<div id="' . $honey_name['name'] . '_wrap" style="display:none;">' .
'<form method="post" action="some action here">' .
'<input type="text" ' . $this->attributes($honey_name) . ' id="' . $honey_name['name'] . '" />' .
'<input type="text" ' . $this->attributes($honey_time) . ' value="' . $honey_time_encrypted . '" />' .
'</form></div>';
好的,我明白了。 Angular 不会 post 空表单字段,所以这是问题的一部分。
第二个问题与 formData.my_time
有关。如果你打算在服务器端设置输入值,那么你必须使用ng-init="foo = 'bar'" ng-model="foo"
.
所以一旦我添加 ng-init="formData.my_time = \'' . $honey_time_encrypted . '\'"
我就可以开始了。
所以我有一个函数可以在 Laravel.
中生成蜜罐表单字段问题是当我使用 Angular 提交表单时,javascript object 不包含 my_time 或 my_name 字段。
public function generate(array $honey_name, array $honey_time)
{
$honey_time_encrypted = parent::getEncryptedTime();
// Encrypt the current time
$html = '<div id="' . $honey_name['name'] . '_wrap" style="display:none;">' .
'<input type="text" ' . $this->attributes($honey_name) . ' id="' . $honey_name['name'] . '" />' .
'<input type="text" ' . $this->attributes($honey_time) . ' value="' . $honey_time_encrypted . '" />' .
'</div>';
echo $html;
}
有什么想法吗?
更新:
Blade 模板
<form ng-submit="submitForm(formData)">
<div class="form-group form-group-lg">
{!! Form::text('name', null, ['class' => 'form-control', 'placeholder' => 'Name', 'ng-model' => 'formData.name']) !!}
{!! Honeypot::generate(['name' => 'my_name', 'ng-model' => 'formData.my_name'], ['name' => 'my_time', 'ng-model' => 'formData.my_time']) !!}
</div>
<div class="form-group form-group-lg">
{!! Form::email('email', null, ['class' => 'form-control', 'placeholder' => 'Email', 'ng-model' => 'formData.email']) !!}
</div>
<div class="form-group form-group-lg">
{!! Form::text('subject', null, ['class' => 'form-control', 'placeholder' => 'Subject','ng-model' => 'formData.subject']) !!}
</div>
<div class="form-group">
{!! Form::textarea('message', null, ['class' => 'form-control', 'rows' => '5', 'placeholder' => 'Message', 'ng-model' => 'formData.message']) !!}
</div>
<div class="form-group">
{!! Form::submit('Send', ['class' => 'btn btn-default center-block']) !!}
</div>
</form>
提交的表单数据:
$scope.submitForm = function(formData) {
console.log(formData);
Contact.submit(formData).then(function(results) {
SweetAlert.swal({
title: "Success!",
text: "Thanks for getting in touch! I usually respond within 12 hours.",
type: "success",
});
});
};
// Output of console.log();
Object {name: "Daniel", email: "abc@123.com", subject: "asdsadsafas fasfaf", message: "asjfasf aalhfsfa flaskfh aklsflakf a"}
所以它缺少 my_time
和 my_name
模型,这导致验证失败。
您没有 <form>
元素。
这样试试:
$html = '<div id="' . $honey_name['name'] . '_wrap" style="display:none;">' .
'<form method="post" action="some action here">' .
'<input type="text" ' . $this->attributes($honey_name) . ' id="' . $honey_name['name'] . '" />' .
'<input type="text" ' . $this->attributes($honey_time) . ' value="' . $honey_time_encrypted . '" />' .
'</form></div>';
好的,我明白了。 Angular 不会 post 空表单字段,所以这是问题的一部分。
第二个问题与 formData.my_time
有关。如果你打算在服务器端设置输入值,那么你必须使用ng-init="foo = 'bar'" ng-model="foo"
.
所以一旦我添加 ng-init="formData.my_time = \'' . $honey_time_encrypted . '\'"
我就可以开始了。