jeudi 16 avril 2015

2 submit buttons on html form

I have 2 submit buttons on 1 form



<form action="main.php" method="POST" id="form" name="form">
<div id="box" name="box" style="-webkit-transition:1s;overflow:hidden;">
<label class="boxes"><input type="checkbox" id="All" name="All" onclick="checkAll()" /><span>All</span></label>
<label class="boxes"><input type="checkbox" id="books" name="books" onclick="rmOthers(1)"/><span>Books</span></label>
<label class="boxes"><input type="checkbox" id="journals" name="journals" onclick="rmOthers(2)"/><span>Journals</span></label>
<label class="boxes"><input type="checkbox" id="guidelines" name="guidelines" onclick="rmOthers(3)"/><span>Guidelines</span></label>
<label class="boxes"><input type="checkbox" id="pe" name="pe" onclick="rmOthers(4)"/><span>Patient Education</span></label>
</div>
<button type="button" class="submit" id="hide" style="padding:15px 20px;" onclick="hideBoxes()">+</button><input type="search" name="search" class="inputs" placeholder="Search Articles" value="<?php echo isset($_POST['search']) ? $_POST['search'] : ""; ?>" /><button type="submit" name="submit" class="submit" >Search</button><br />
<div id="sq">
<select id="sqType" style="width:5%;">
<option class="ar">And</option>
<option class="ar">Or</option>
</select>
<input type="text" class="inputs" placeholder="Filter Results" name="filter" style="width:70%;" value='<?php echo (isset($_POST['filter']) ? $_POST['filter'] : ''); ?>'/>
<button type='submit' id="fil" class="submit" style="-webkit-transform:translateX(-5px) translateY(-3px); width:7%;" >Filter</button>
</div>
</form>


now my problem is when i submit the form using the 2nd submit button my php code displays a blank data.


here's my php code



if(isset($_POST['submit']))
{
$search = $_POST['search'];

$sql = (strcmp($search, "") == true ? "SELECT * FROM `tbl_article_abstract` WHERE `title` LIKE '%$search%'" : "SELECT * FROM `tbl_article_abstract` WHERE `title` LIKE '%$search%' LIMIT 30");

$query = mysqli_query($con, $sql);
if(mysqli_num_rows($query) != 0)
{

while($run = mysqli_fetch_assoc($query))
{

$title = (strlen($run['title']) > 121) ? substr($run['title'], 0, strpos(wordwrap($run['title'], 121), "\n")) . '...' : $run['title'];

echo '<div class="SearchResults">';
echo " <span class='top'>";
echo " <a>";
echo " <h3>". strtoupper($title) ."</h3>";
echo " </a>";
echo " <br />";
echo " <h5 class='sub'>";
echo " Authors :<a class='authors'>Dr.Michael Ramsay</a><a class='authors'>Dr.Lars Benitez</a><a class='authors'>Dr.Kevin John Pascual</a><br><br>";
echo " </h5>";
echo " </span>";
echo " <span class='bottom'>";
echo " <span class='bottomLeft'>";
echo ($run['abstract'] != "" ? " <a class='options' onclick='showOverlay(". $run['id'] .")'>Abstract</a><span style='margin:0px 5px;'>|</span>" : "" );
echo " <a target='_blank' href='view.php?filename=NKTI Proceedings vol. 1 no. 1 Feb. 1996' class='options'>";
echo " Full Article";
echo " </a>";
echo " </span>";
echo " <div class='overlay' id='". $run['id'] ."' onclick='hideOverlay(this, event)'> ";
echo " <iframe class='abstract' src='abstract.php?id=".$run['id']."' style='padding:0px;' scrolling='no'>";
echo " <button class='closeButton' onclick='hideOverlay(". $run['id'] .")'>x</button>";
echo " <div class='wrapper'><h3>".$run['title']."</h3></div><br />";
echo $run['abstract'];
echo " </iframe>";
echo " </div>";
echo " <span class='bottomRight'>";
echo " <p class='label'>NKTI Proceedings volume ".$run['volume'].", January - April 2015 @ Pg. 1-15</p>";
echo " </span>";
echo " </span>";
echo " <br style='clear:both;'/>";
echo "</div>";


}

}

}

?>


My Objective : I want the user to enter a search string, and if the user cannot find what he/she wants on the results they can filter the data retrieved furthermore.


Problem : when the user submits the form using the first submit button the results shows up after that when they submit the form using the 2nd submit button the results are gone.


Aucun commentaire:

Enregistrer un commentaire