限制用户表单提交

时间:2014-03-12 20:52:59

标签: php forms limit submission

我使用简单的表单发送一些数据。用户必须登录才能访问表单(我有一个包含用户和密码的数据库)。

我想要做的是限制用户成功提交表单的次数,并且基于这样的响应:mysite.com/send.php?code=0(其中0表示成功和其他值将是一个错误)。

我可以手动在数据库中添加此限制,但我真的不知道如何解决这个问题。

1 个答案:

答案 0 :(得分:0)

以下是您可以如何使用所需功能的示例。如果不确切知道您遇到问题的哪些部分,这是我能做的最好的事情。如果不清楚,请提问。

HTML表单

<form method="post" action="myUrl">
    <input name="myField"/>
    <input type="submit"/>
</form>

PHP来处理表单

if(isset($_POST["myField"])){
    if(userHasNotSubmittedForm($_SESSION["userIdOrSomething"])){
        //update the column here with a database query
    }
    else{
        //tell the user they have already submitted this form.
        //Ideally, the user shouldn't be able to see this page
        //if they have already submitted this form, but this
        //behavior matches what you asked for.
    }
}
相关问题