Swarup Koley
Swarup Koley

Reputation: 27

When I auto submit the from its create a infinity loop how can i stop

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

Answers (2)

user11468319
user11468319

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

Qirel
Qirel

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

Related Questions