Last active
October 6, 2015 09:16
-
-
Save kas-cor/ff252f61014f9815d159 to your computer and use it in GitHub Desktop.
Check form
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form action="server.php" method="POST" id="contact_form"> | |
<input type="hidden" name="check_filelds" value="email,name,text" /> | |
<input type="hidden" name="check_form" value="" /> | |
<input type="text" name="email" value="" /> | |
<input type="text" name="name" value="" /> | |
<textarea name="text" rows="4" cols="20"></textarea> | |
<input type="button" name="send" value="send" onclick="checkAndSendForm($('#contact_form'))"/> | |
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function checkAndSendForm(objform) { | |
$.post("/data.php", "act=check_form&" + $(objform).serialize(), function (res) { | |
$("input[name=check_form]").val(res); | |
$(objform).submit(); | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function genCheckForm($data) { | |
$ret = ""; | |
if (!empty($data['check_filelds'])) { | |
foreach (explode(",", $data['check_filelds']) as $field) { | |
$ret.=$data[$field]; | |
} | |
} else { | |
return md5(uniqid(time())); | |
} | |
return md5("sdgf4fhdfhw4sdeg" . $ret); | |
} | |
// Generate code | |
if ($_POST['act'] == "check_form") { | |
echo genCheckForm($_POST); | |
exit(); | |
} | |
// Check form | |
if ($_POST['check_form'] != genCheckForm($_POST)) { | |
echo "Invalid form!"; | |
exit(); | |
} else { | |
echo "Valid form!"; | |
exit(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment