I have created a module for Expression Engine 3, which includes two functions.

  1. search_form
  2. search_results

search_form returns a form into my template.

search_entries is actioned by search_form upon the forms submission. This function then completed my queries, returning an array of entry_id.

My question, is how can I then return those entry ids back to the template, and output them through a channel entries tag?

1 Answer 1


I had similar situation this week. I've made two functions - one for the form template tag and second is action callback that works with form data.

In this manner I could output information with ee()->output->show_message(). Like this:

$data = array(
  'title' => 'Search Results',
  'heading' => 'Search Results',
  'content' => "content as a string. wrapped as system message"

That was not what I was looking for :( So I've switched to post->redirect->get pattern and added another template tag for showing search results.

In general, now I have 3 methods inside base module class:

search_form constructs html for the form and returns it

search_submit is processing data passed after form submit, saves results into $_SESSION variable and redirects user to template with search results tag.

search_results reads data from $_SESSION, creates $variables array and returns it with ee()->TMPL->parse_variables(ee()->TMPL->tagdata, $variables).

class Custom_search {
  function search_form() {
    $action_id = ee()->functions->fetch_action_id('Custom_search', 'search_form_submit');
    $form_data = array(
      'action' => ee()->functions->create_url(ee()->uri->uri_string),
      'hidden_fields' => array(
         'ACT' => $action_id,
         'return_url' => ee()->functions->create_url('template_group/search_results')
    $tag_data = ee()->TMPL->tagdata;
    $form = ee()->functions->form_declaration($form_data) . $tag_data . "</form>";
    return $form;

  function search_form_submit() {
    //do something with input
    $_SESSION['custom_search']['query'] = "search query here";
    $_SESSION['custom_search']['results'] = $results;

  function search_result() {
    //create $vars array from your results here
    return ee()->TMPL->parse_variables(ee()->TMPL->tagdata, $vars);

And you'll have two template files - one with search form template tag

  <input type="text" placeholder="Search..." name="query" />
  <input type="submit" name="submit" value="go" />

and another with results tag

  <p>Your query: {query}</p>
  <p>Results found: {total_results}</p>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.