i have a page with 2 forms. This is for insert into db using PHP/PDO. The problem I'm facing is that the IF statement on the insert page is producing an error, even though I have not pressed the submit button. Have tried several ways with $_POST isset/ !==0 and so on. No luck so far.
Can there be a problem with the jQuery/FORM-combo? Maybe that's triggering the $_POST?
jQuery for choosing forms:
<script type="text/javascript">
$(document).ready( function() {
$('#formSel').change( function() {
var id = $(this).val();
if( id != '-' )
{
$('form').hide();
$('#form'+id).show();
//$('#myModal').modal('show');
}
});
});
</script>
The forms are set up like this:
<div>
<select class="form-control input-small" id="formSel">
<option value="-">Choose category</option>
<option value="One">One</option>
<option value="Two">Two</option>
</select>
</div>
<!-- Form One -->
<form id="One" style="display:none" method="POST" action="insert.php">
<input type="text" id="aaa" placeholder="aaa">
<input type="text" id="bbb" placeholder="bbb">
<button type="submit" value="btn-One">Submit</button>
</div>
<!-- Form Two -->
<form id="One" style="display:none" method="POST" action="insert.php">
<input type="text" id="ccc" placeholder="ccc">
<input type="text" id="ddd" placeholder="ddd">
<button type="submit" value="btn-Two">Submit</button>
</div>
To insert the data I have a second page (insert.php) containing the PHP/PDO. This is set up to execute when submit button is pressed:
if ($_SERVER['REQUEST_METHOD'] == 'POST' && (!empty($_POST['btn-One']))) {
//execute code
}
else {
echo 'Error submit One';
}
if ($_SERVER['REQUEST_METHOD'] == 'POST' && (!empty($_POST['btn-Two']))) {
//execute code
}
else {
echo 'Error submit Two';
}
I'm all out of ideas and skills to see the solution. Hopefully someone can spot what is triggering the forms.
name
attribute is missing inform and form element
– Saty