php - how to let the form remember the values i put -


 <form name="search" method="post" >  seach for: <input type="text" name="find" /> in  <select name="field">  <option value="category1">category1</option>  <option value="category2">category2</option>  </select>  <input type="submit" name="search" value="search" />  </form>  <?php     if(!empty($_post)){         $options = array('category1'=> array('1' => 'dog', '2' => 'cat'), 'category2' =>array('1'=>'flower', '2'=>'grass'));         $input = trim($_post['find']);         $category = $_post['field'];         $output = $options[$category][$input];         echo $output; } ?> 

question:

if input 1 , select 'category2', shows:flower, input filed became empty, , select box went 'category1', there way can let input box , select box keep value put there, in case, after click submit botton, '1' still in input field, , 'category2' shows in select box.

use value="<?php if(isset($_post[])) echo $_post[]; ?>"

<form name="search" method="post" >  seach for: <input type="text" name="find" value="<?php echo (isset($_post['find']) ? $_post['find'] : ''); ?>" /> in  <select name="field">  <option value="category1" <?php echo (isset($_post['field']) && $_post['field'] === 'category1') ? 'selected="selected"': ''; ?>>category1</option>  <option value="category2" <?php echo (isset($_post['field']) && $_post['field'] === 'category2') ? 'selected="selected"': ''; ?>>category2</option>  </select>  <input type="submit" name="search" value="search" />  </form> 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -