Reputation: 27
The from action must be the same page how can I just click once. And remove the loop
<form action="" name="formsajal" method="post" enctype="multipart/form-data" id="formsajal">
<?php
$execute = "<input id='submitted' type='submit' value='submit' title='Ctrl+Enter'>";
echo $execute;
?>
</form>
<?php echo "<script>document.getElementById('submitted').click();</script>"; ?>
Upvotes: 0
Views: 57
Reputation:
Here is the code have name attribute for your submit
<?php
if (isset($_POST['submitted'])) {
//Do your after submit stuffs here
} else {
?>
<form action="" name="formsajal" method="post" enctype="multipart/form-data" id="formsajal">
<?php
$execute = "<input name='submitted' id='submitted' type='submit' value='submit' title='Ctrl+Enter'>"; //set name attribute
echo $execute;
?>
</form>
<?php echo "<script>document.getElementById('submitted').click();</script>"; ?>
<?php } ?>
Upvotes: 0
Reputation: 26460
Give your input a name, so that the form submits a value. Only inputs, selects and textareas with a name attribute is sent over POST/GET when the form is submitted.
You can now check if the form was sent, by checking if that name is present in the $_POST
array. If it is present, don't re-submit the form.
<form action="" name="formsajal" method="post" enctype="multipart/form-data" id="formsajal">
<input id='submitted' name="submitted" type='submit' value='submit' title='Ctrl+Enter'>
</form>
<?php
if (!isset($_POST['submitted'])) {
echo "<script>document.getElementById('submitted').click();</script>";
}
?>
Upvotes: 1