Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using hidden value instead of $_GET or $_REQUEST

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?

like image 425
Sam Khan Avatar asked Nov 08 '11 16:11

Sam Khan


People also ask

How do you get hidden inputs?

The <input type="hidden"> defines a hidden input field. A hidden field let web developers include data that cannot be seen or modified by users when a form is submitted. A hidden field often stores what database record that needs to be updated when the form is submitted.

How do you assign a value to a hidden field?

In jQuery to set a hidden field value, we use . val() method. The jQuery . val() method is used to get or set the values of form elements such as input, select, textarea.

How do I hide hidden fields in inspect element?

It is not possible to hide elements from the DOM inspector, that would defeat the purpose of having that tool. Disabling javascript is all it would take to bypass right click protection. What you should do is implement a proper autologin.


1 Answers

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>
like image 63
Treffynnon Avatar answered Oct 03 '22 20:10

Treffynnon