I'm new to jQuery, and just wondering if there's a way to detect if a form has been submitted on page load, and if so parsing some code.
I have:
<form action="/login/register" method="post">
<input type="text" value="Username" name="regName"/>
<input type="password" value="Password" name="regPass"/>
<input type="submit" value="Register"/>
</form>
and:
<?php
if (isset($_POST['regName']))
{
//check inputs and add account
}
?>
But i was wondering if i could check if the form had been submitted via jQuery?
Thanks.
I'm new to jQuery, and just wondering if there's a way to detect if a form has been submitted on page load, and if so parsing some code.
I have:
<form action="/login/register" method="post">
<input type="text" value="Username" name="regName"/>
<input type="password" value="Password" name="regPass"/>
<input type="submit" value="Register"/>
</form>
and:
<?php
if (isset($_POST['regName']))
{
//check inputs and add account
}
?>
But i was wondering if i could check if the form had been submitted via jQuery?
Thanks.
Share Improve this question edited Feb 6, 2014 at 14:14 John Conde 220k99 gold badges463 silver badges502 bronze badges asked Apr 20, 2012 at 15:26 user1169601user1169601 292 silver badges5 bronze badges1 Answer
Reset to default 7Just have PHP set a javascript variable to true if a POST submission was made. Then jQuery just needs to check its value.
<script type="text/Javascript">
var was_posted = <?php echo ('POST' === $_SERVER['REQUEST_METHOD']) ? 'true' : 'false'; ?>
</script>
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744755251a4591841.html
评论列表(0条)