如何解决如何使用silverstripe中的成功消息重定向返回自定义html表单?
我是 SilverStripe 的新成员。我想在 SilverStripe 中创建自定义 HTML 表单。
<form class="form-inline" $HelloForm.FormAttributes>
<p id="{$HelloForm.FormName}_success" class="message" style="">$HelloForm.Message</p>
<div class="form-group">
<label for="email">Email:</label>
<input type="text" class="form-control" id="email" placeholder="Enter email" name="email">
</div>
<div class="form-group">
<label for="pwd">Password:</label>
<input type="password" class="form-control" id="pwd" placeholder="Enter password" name="pwd">
</div>
<div class="checkBox">
</div>
$HelloForm.fields
<input type="hidden" value="{$AbsoluteLink}" name="redirectURL" class="action" id="{$HelloForm.FormName}_action_doSayHello"/>
在我的控制器中
public function HelloForm()
{
$form = Form::create(
$this,'HelloForm'
);
$actions = new FieldList(
FormAction::create('doSayHello','Submit')->setAttribute('class','btn btn-success')
);
$form = new Form($this,'HelloForm',$actions);
return $form;
}
public function doSayHello($data,$form)
{
$form->sessionMessage('thanks for contact us','good');
return $this->redirectBack();
//i am not getting success message after submit
}
在这种情况下,我提交后会收到成功信息吗?
当我使用标准的 SilverStripe 表单时,它可以工作,但是当使用上面的自定义 HTML 表单时,我被卡住了
解决方法
您可以通过ajax提交表单,这有很多好处。
- 页面不必自行刷新
- 您可以在提交后通过向上滑动或某种类似的动画制作表单动画。
- 您可以处理
success
或error
等表单状态
一些示例代码(在 jQuery 中):
let form = $('.form-inline');
$(form).ajaxSubmit({
success: function() {
$(form).slideUp();
$('#form-state').text("Successfully submitted form.");
}
})
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。