0

Hey guys i am trying to write simple search in database using Nette Framework, my Presenter (controller) looks like this:

<?php
   public function searchsucceeded($searchword)
    {
    $selection = $this->database->findAll->select('*')->where("name LIKE ?", "%$searchword%");
    return $selection;
    }

    protected function createComponentsearchForm()
    {
        $form = new Form;
        $form->addText('name', 'Vyhladať ban, vložte nick zabanovaného hráča')
            ->setRequired('Vyhladať ban, vložte nick zabanovaného hráča');
        $form->addSubmit('search', 'Hľadať')
            ->setAttribute('class', 'default')
            ->onSuccess[] = $this->searchsucceeded;
    }

?>

To say true i am not even 100% sure that if its right, but it should be, what i need is to add it to let form use this function when i press SEARCH button and not to redirect to old search script.

My serach form:

<form action="index.php" method="POST">
  <input type="text" style="margin-top:10px;" placeholder="Vyhľadať ban... (Zadajte nick hráča)" name="nickS" class="span10" required="required">
  <input type="submit" value="Hľadať" name="sSubmit" class="btn btn-primary span2">
</form>

I am absolutly new in OOP and Nette as well so this question is prolly totaly noobish, i know how to simple do it without OOP but i prefer this option!

So is someone here who can help me?

Radek Simko
  • 15,886
  • 17
  • 69
  • 107
user3009924
  • 59
  • 2
  • 14
  • Welcome to StackOverflow! While experimenting with frameworks might give insights on how OOP is applied to different concepts (if done right), I would also recommend studying a tutorial focused on OOP. – ComFreek Nov 19 '13 at 17:45

1 Answers1

0

I would recommend you to use redirect in searchsucceeded method. This is more from business look than programming recommendation.

You will probably use search form on many pages on website and than you will present results only on one type of page. For SEO is also good to present results on unique page, for example test.com/s/.

Tomas Zaruba
  • 196
  • 1
  • 8