Submit data in PHP using hidden fields or query string parameters

时间:2017-10-12 09:55:01

标签: php submit

I'm looking for the best way to submit form parameters in PHP.

Send parameters in the URL:

<form method="post" 
      class="form-validate-jquery" 
      action="suppliers_sql.inc.php?a=edit_ctt&ctt_id=<? echo $supplier_contact_id ?>"
>
</form>

Send parameters in hidden fields:

<form method="post" class="form-validate-jquery" action="suppliers_sql.inc.php">                                        
<input type="hidden" name="a" value="edit_ctt" />
<input type="hidden" name="supplier_contact_id" value="<? echo $supplier_contact_id ?>" />
</form>

Which one is best?

1 个答案:

答案 0 :(得分:3)

It much depends on the situation and both approaches are valid.

Personally I prefer to use hidden fields if possible, because of several reasons:

  • GET parameters have limited length, although that may not be a problem for you right now...
  • If you ever want to make those fields visible, migration should be a bit easier...
  • If you have some sort of validation in place for form fields, applying that validation to the hidden fields should be simpler...
  • It just looks a bit cleaner and easier to read...