I have been using hidden values for forms.
Example:
<form method="post" action="page.php">
<input type="text" name="name""
<input type="hidden" name="book_id" value="$bookid">
<input type="button">
</form>
$bookid
is the $_GET
value for book.php?id=34324
So instead of doing page.php?id=$bookid
I am using $bookid
in hidden field.
My Question: Is it harmful if i use hidden values vs using $GET
or $POST
in the form action?
To answer your question: no it is not harmful to use hidden inputs in this way.
To fix the supplied code you need to give your hidden input a name and change the method to GET
:
<?php
if(array_key_exists('id', $_GET)) {
$bookid = (int) $_GET['id'];
}
?>
<form method="get" action="page.php">
<input type="text" name="name">
<input type="hidden" name="id" value="<?php echo $bookid; ?>">
<input type="button">
</form>