submit form to self
At the moment, I have a form with an input (text) and a button to submit the form.
The form is posted to 'submit.php'. I would like the form post开发者_运维技巧ed to same page as the form.
How can I do this?
<form action="submit.php" method="POST">
<input type="text" class="emailField" placeholder="email address" name="email" />
<button type="submit">
<div class="submit" />
</button>
</form>
submit.php
<?php
mysql_connect('localhost', '', '') or die('unable to connect');
mysql_select_db('') or die('unable to select db');
$query = mysql_query("");
if (mysql_num_rows($query) > 0) {
exit("You have already subscribed!");
}
else {
mysql_query("") or die(mysql_error());
exit("You have successfully subscribed!");
}
?>
I think you have a couple of options here.
Submit the form onto itself
<?php
if('POST' == $_SERVER['REQUEST_METHOD']) {
// process the form here
}
?>
<form action="" method="POST">
<input type="text" class="emailField" placeholder="email address" name="email" />
<button type="submit">
<div class="submit" />
</button>
</form>
Redirect back to the form
Add something like this in submit.php
where you want to show the form.
<?php
header('Location: http://example.org/form.php');
exit;
?>
精彩评论