I have several forms on my single PHP page. All look like this:
<form id="test_form_1" action="test_submit.php" method="post" name="test_form">
<label>This is Question #1:</label>
<p>
<label>
<input type="radio" name="Question1" value="ans1" id="Question1_0">
Answer1</label>
<br>
<label>
<input type="radio" name="Question1" value="ans2" id="Question1_1">
Answer2</label>
<br>
<button type="submit" name="btnSubmit" id="btnSubmit">Submit</button>
</form>
But ID
of each form is different, like test_form_1
, test_form_2
, test_form_3
, and so on. I am calling these forms via HEREDOCS once PHP decide which ID the user belongs to.
Then I am using a JavaScript to automatically submit the form after 5 seconds.
<script>
window.setTimeout(function() {
document.getElementById('test_form_1').submit();
}, 5000);
</script>
Here are the HEREDOCS:
$test1= <<<HTML
<table>Month 1 Test.</table>
HTML;
$test2= <<<HTML
<table>Month 2 Test.</table>
HTML;
//and so on...
And here is the PHP part:
<?php
if($user_category == test1){
echo"test1";
}
if($user_category == test2){
echo"test2";
}
My question: Is it possible to pass ID
to getElementById
of that form only to which the user actually belongs? So that it only submits that form to the database to which the user actually belongs. Or is there any better alternative to achieve this?