Jayesh Duggal
Jayesh Duggal

Reputation: 81

Adding field to form in HTMl and PHP

I have a form in html with php code inside which looks like this

<form name="category" action="search.php" method="get" enctype="multipart/form-data">
    <select class="form-control2" name="category_name" id="category_name" onchange="category.submit();">
    <option value="0">Select Category</option>
      <?php while($cat_data=mysql_fetch_array($cat_res)){?>
      <option value="<?php echo $cat_data['Category_Name'] ?>"><?php echo $cat_data['Category_Name'] ?></option>
      <?php }?>
    </select>
</form>

With this I get URL like

 /search.php?category_name=USA

I want to add another field in URL so the URL look like

/search.php?cat_name=1&category_name=USA

This field cat_name must be updated from mysql and not from form in real time depending what option is selected. Is it possible in php and html

Upvotes: 1

Views: 283

Answers (3)

Ninju
Ninju

Reputation: 2530

Use hidden input field in the form

<form name="category" action="search.php" method="get" enctype="multipart/form-data">
    <input type="hidden" name="name" value="1" />
</form>

Upvotes: 0

Ali Idrees
Ali Idrees

Reputation: 598

Just add a hidden input field before your closing form tag

<input type="hidden" name="cat_name" value="<?php echo cat_name; ?>" />

Upvotes: 0

Rohit Kumar
Rohit Kumar

Reputation: 1958

Two possible solutions - first add query string in action of form

<form name="category" action="search.php?cat_name=1"
 method="get" enctype="multipart/form-data">

Alternatively , append a input type hidden or as you need .

<form name="category" action="search.php" method="get" enctype="multipart/form-data">
    <select class="form-control2" name="category_name" id="category_name" onchange="category.submit();">
    <option value="0">Select Category</option>
      <?php while($cat_data=mysql_fetch_array($cat_res)){?>
      <option value="<?php echo $cat_data['Category_Name'] ?>"><?php echo $cat_data['Category_Name'] ?></option>
      <?php }?>
    </select>
<input type="hidden" name="cat_name" value="1" />
</form>

Upvotes: 3

Related Questions