Welcome Guest, Not a member yet? Register   Sign In
Search Criteria Ignored, Only Redirects to Else Statement
#13

(06-13-2019, 02:16 PM)jreklund Wrote: We needed to see what you got into your controller, to see where the problem where in the first place. As you didn't get any information from it, we can fix the controller or the view.

Your searchform output are this:
<input type="submit" name="" value="submit" class="button">

Login form:
<input type="submit" name="submit" value="Login"/>

As you can see the name="" field are empty, and that's why your $this->input->post('post') never validated.

If you want your old code, use this instead in your view.
echo form_submit('submit', 'submit', 'class="button"');

___________________EDIT______________________

Hold on a second... I can't even see how you got the following:
<input type="submit" name="" value="submit" class="button">

With your provided code you should have:
<input type="submit" name="submit" value="" class="button">

But none the less, your field are empty. And an empty value can't be matches as true in an if statement. You can reverse it with ! in case you want an empty button.

___________________EDIT2______________________

Or match it with an empty string. if($this->input->post('submit') === '') {

Okay, so I added those changes but I still get a Parse Error.

Recipe.php Search Controller:
PHP Code:
function search(){
 
  if($this->input->method() === 'post')
 
   $search $this->input->post('query');
 
  $results $this->recipe_model->search($search);
 
     $data = array(
 
     'title' => "Shirley's Recipes : Search Results",
 
     'columns' => array('toc''recipe_search'),
 
     'recipes' => $results,
 
  );
 
  $this->load->view('includes/template'$data);
 
  }
 
  else{
 
   redirect('recipe');
 
  }
 } 

Recipe_model.php Search Model:
PHP Code:
function search($search){
 
 $terms explode(" "$search);
 
 $match "";
 
 foreach($terms as $term){
 
  $match .=  $term;
 
 }
 
 $querystr "SELECT *, MATCH(name, linkname, ingredients, equipment, preparation, directions, category, subcategory, keywords) AGAINST('".$match."') as score FROM recipe WHERE MATCH(name, linkname, ingredients, equipment, preparation, directions, category, subcategory, keywords) AGAINST('".$match."') ORDER BY score DESC;";
 
 $q $this->db->query($querystr);
 
 return $q->result();
 } 

Recipe.php View:
Code:
  <div id="searchform" class="box noprint">
   <?php
    echo form_open('recipe/search', array('class' => 'form'));
    echo form_input(array('name' =>'query','onfocus' => "this.value = '';", 'onblur' => "if(this.value == ''){this.value ='Recipe Search'}", 'value' => 'Recipe Search'));
    echo form_submit('submit', 'submit', 'class="button"');
    echo form_close();
   ?>
 </div>  

Recipe_search.php View
Code:
<div id="recipelist" class="content">
<h1>Recipe Search</h1>
 <div class="recipesearch">
  <ol>
   <?php if(!empty($recipes)): foreach($recipes as $recipe): ?>
    <li><a href="/recipe/<?=$recipe->id ?>"><?=$recipe->name ?></a><span class="confidence"><?=$recipe->score ?></span></li>
    <?php endforeach; ?>
  </ol>
 </div>
 <?php else: ?>
 <h3>No matching recipes</h3>
 <?php endif; ?>
</div>

Parse Error:
PHP Code:
An uncaught Exception was encountered

Type
ParseError

Message
syntax errorunexpected 'else' (T_ELSE), expecting function (T_FUNCTION) or const (T_CONST)

Filename: /home/www/shirleysrecipes.100webspace.net/application/controllers/Recipe.php

Line Number
62

Backtrace
:

File: /home/www/shirleysrecipes.100webspace.net/index.php
Line
315
Function: require_once 

Am I still missing something? Thank you for your dedication!
Reply


Messages In This Thread
RE: Search Criteria Ignored, Only Redirects to Else Statement - by Josh1985 - 06-13-2019, 05:21 PM



Theme © iAndrew 2016 - Forum software by © MyBB