Show "No Results Found" Only After Hitting Enter

languages

#1

Hi there, I’m currently building a search engine for a website I’m making.
The issue is whenever I click on the search tab the “No Results Found” message immediately appears. How do I make it so that it appears only after someone has used the search bar?

I’m using the code found on Kirby’s Documentation Page and code found on this solution.

<?php if($results->count()) : ?>
  <ul class="searchresults">
    <?php foreach($results as $result): ?>
      <li>
        <a href="<?php echo $result->url() ?>">
         <?php echo $result->title()->html() ?>
        </a>
      </li>
    <?php endforeach ?>
  </ul>
<?php else : ?>
  <p>There are no results</p>
<?php endif ?>

#2

Wrap an if statement around your code block that checks if a search request was sent:

<?php if(get('q')): ?>
  <?php if($results->count()) : ?>
    <ul class="searchresults">
      <?php foreach($results as $result): ?>
        <li>
          <a href="<?php echo $result->url() ?>">
           <?php echo $result->title()->html() ?>
          </a>
        </li>
      <?php endforeach ?>
    </ul>
  <?php else : ?>
    <p>There are no results</p>
  <?php endif ?>
<?php endif ?>

#3

Sorry for the late response. This worked perfectly! Thanks :slight_smile: