Jump to content

Have a problem with form .. i am trying to make search form please help


yanivkalfa

Recommended Posts

well my problem is this . i want to have search in website through my database i am using Simple form to send the needed values to another page. my problem is i want the value to stay in the text field even after i clicked submit in the search page .

<form action="search.php" method="POST" name="gobutt">
<div id="Sem"></div>
<input name="search" type="text" class="seach" />
<div id="checkv">
<input type="checkbox" name="relaible" checked="rel" class="styled" />
</div>

<?php
if($_GET["adv"] == 1){
?>
<div id="checkMov">
<input type="checkbox" name="relaible" checked="mov" class="styled" />
</div>
<div id="checkgam">
<input type="checkbox" name="relaible" checked="gam" class="styled" />
</div>
<div id="checkapp">
<input type="checkbox" name="relaible" checked="app" class="styled" />
</div>
<div id="checkMus">
<input type="checkbox" name="relaible" checked="mus" class="styled" />
</div>
<div id="checkebok">
<input type="checkbox" name="relaible" checked="ebook" class="styled" />
</div>
<div id="checkexp">
<input type="checkbox" name="relaible" checked="exp" class="styled" />
</div>
<input name="adv" type="text" class="seachc" value="<?php echo $advornot; ?>"  />
<?php
}
else
{
?>
<input name="adv" type="text" class="seachc" value="<?php echo $advornot; ?>"  />
<?php
}
?>
<input type="submit" name="submit" value=" "  class="gob"/>
</form>

 

ignore the PHP part its just something i had to do for advanced search options not related to this problem

 

thanks in advanced realy much

Link to comment
Share on other sites

<form method="POST">

 

doesn't valid with strict xhtml --> "POST" should be lowercase - "post".

 

To solve your problem, you need to fetch the submitted variable through the post array.

 

<?php

if ( isset($_POST['submit'])) {

$search_term = $_POST['adv'];

// form submitted, show searched term

echo '<input type="text" name="adv" ... value="';

echo $search_term;

echo '" />';

}
else {

// original form

}

?>

Link to comment
Share on other sites

Yea but would it then be able to actualy edit the text field my self ?.. i mean lets say like this..

you start page . fill in matrix for EG click on search . then on the other page i move this variable to another variable and put it back into that same text .. will that person be able to Click on this form again and preform search ?

i give EG now

if ( isset($_POST['submit'])) {

$search_term = $_POST['adv'];

// form submitted, show searched term

echo '<input type="text" name="adv" ... value="';

echo $search_term;

echo '" />';// here i basicaly put into value the search enteri someone put in  <input type="text" name="adv" ... value=""/> now wil //that person be able to actualy click on this again ? and set his Own search and not his previus 1 ?

}
else {

<form action="search.php" method="POST" name="gobutt">
<div id="Sem"></div>
<input name="search" type="text" class="seach" />
<div id="checkv">
<input type="checkbox" name="relaible" checked="rel" class="styled" />
</div>

<?php
if($_GET["adv"] == 1){
?>
<div id="checkMov">
<input type="checkbox" name="relaible" checked="mov" class="styled" />
</div>
<div id="checkgam">
<input type="checkbox" name="relaible" checked="gam" class="styled" />
</div>
<div id="checkapp">
<input type="checkbox" name="relaible" checked="app" class="styled" />
</div>
<div id="checkMus">
<input type="checkbox" name="relaible" checked="mus" class="styled" />
</div>
<div id="checkebok">
<input type="checkbox" name="relaible" checked="ebook" class="styled" />
</div>
<div id="checkexp">
<input type="checkbox" name="relaible" checked="exp" class="styled" />
</div>
<input name="adv" type="text" class="seachc" value="<?php echo $advornot; ?>"  />
<?php
}
else
{
?>
<input name="adv" type="text" class="seachc" value="<?php echo $advornot; ?>"  />
<?php
}
?>
<input type="submit" name="submit" value=" "  class="gob"/>
</form>

}

 

Hope you understand my problem

Link to comment
Share on other sites

Once they submit the form, they see the original value they inputted into the search box. But after the first search - they can (and will) alter the original value to a new one. PHP will refresh the new search term. You may want to read about $_POST. For instance, the $_POST array (the thing containing your search term) will only save that info for one page refresh. Afterwards, it is refreshed. This way, you will always have the new term that was searched for.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.