如何让用户按时点击按钮然后禁用按钮点击? (拉拉维尔 8)
我有 Laravel 项目(投票系统),它允许用户为表单投票,
我的问题是,如何防止用户为每个表单多次投票?
这是用户数据库:
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('student_id');
$table->string('student_faculity');
$table->string('email')->unique();
$table->string('usertype')->nullable();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();
$table->foreignId('current_team_id')->nullable();
$table->string('profile_photo_path', 2048)->nullable();
$table->timestamps();
});
}
这是表单表:
public function up()
{
Schema::create('files', function (Blueprint $table) {
$table->id();
$table->string('name')->nullable();
$table->string('file_path')->nullable();
$table->string('name_as_id')->nullable();
$table->string('email')->nullable();
$table->string('position')->nullable();
$table->text('bio')->nullable();
$table->string('approve')->nullable();
$table->string('votes')->default('0');
$table->string('image')->nullable();
$table->timestamps();
});
}
表单 balde(投票按钮):
<form method="post" id="my-form" action="{{ route('votes.upVote', $row->id) }}">
@method('PUT')
@csrf
<input id="btn-submit" class="" name="submitbutton" value="Vote" type="submit">
</form>
“我正在使用 foreach 循环来显示所有表单”
表单控制器(投票功能):
public function upVote(Request $request, $id)
{
File::find($id)->increment('votes', 1);
return redirect()->back();
}
有没有一种方法可以阻止用户向投票按钮发送垃圾邮件?
注意:用户可以为每个表单投票一次,因此如果用户投票给特定表单,则不会禁用其他表单的投票按钮,
实现此目的的最佳方法是什么?
I have Laravel project (voting system) that will allow the user to vote for forms
my question here is, how can i prevent the user from voting more than once for each form?
here is the user database:
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('student_id');
$table->string('student_faculity');
$table->string('email')->unique();
$table->string('usertype')->nullable();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();
$table->foreignId('current_team_id')->nullable();
$table->string('profile_photo_path', 2048)->nullable();
$table->timestamps();
});
}
and here is the forms table:
public function up()
{
Schema::create('files', function (Blueprint $table) {
$table->id();
$table->string('name')->nullable();
$table->string('file_path')->nullable();
$table->string('name_as_id')->nullable();
$table->string('email')->nullable();
$table->string('position')->nullable();
$table->text('bio')->nullable();
$table->string('approve')->nullable();
$table->string('votes')->default('0');
$table->string('image')->nullable();
$table->timestamps();
});
}
forms balde (vote button):
<form method="post" id="my-form" action="{{ route('votes.upVote', $row->id) }}">
@method('PUT')
@csrf
<input id="btn-submit" class="" name="submitbutton" value="Vote" type="submit">
</form>
"I'm using foreach loop to display all forms"
forms controller (vote function):
public function upVote(Request $request, $id)
{
File::find($id)->increment('votes', 1);
return redirect()->back();
}
is there a way that i can prevent the user from spamming the vote button?
note: the user can vote once for each form so the vote button won't be disabled for other forms if the user voted for a specific form
what is the best approach to achieve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 jQuery 您可以在提交表单后禁用提交按钮
with jQuery You can disable submit button after submit form