Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-02-2012, 10:21 PM   PM User | #1
neclord02
New to the CF scene

 
Join Date: Oct 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
neclord02 is an unknown quantity at this point
Array value.

First of all, I work on Codeigniter (which isn't really relevant).

Here's the thing, got a search bar which dumps the output into handler.php. It looks like this:

Code:
<div>
    <form class="searchform" action="handler" method="get" name="search">
            <label for="Recipe Search" >Recipe Search: </label>
            <input class="searchfield" type="text" name="query" value="<?php if(isset($data['query']))  {echo ($data['query']);} else {echo "Type your ingredients";} ?>" onfocus="if (this.value == 'Type your ingredients') {this.value = '';}" onblur="if (this.value == '') {this.value = 'Type your ingredients';}" />
            <input class="searchbutton" type="submit" value="Go" />
    </form>
</div>
Then handler.php looks like this:

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class handler extends CI_Controller {

	public function index()
        {
        
        $data['search'] = $this->input->get(NULL, TRUE);
        $data['title'] = array ('Search');
        
        if($data['search'] ==  'Type your ingredients'){$this->load->view('home_view'); }
        else $this->load->view('search_results_view', $data); 
        
        }
  
}
So the searchbar by default always is going to send 'Type your ingredients', unless you actually type something like... carrots, onions, etc...

that is placed as an array to $data['search'] with that function on codeigniter, and I want that when that array is 'Type your ingredients' it triggers the If.

Any help please? <(^.^)>!
neclord02 is offline   Reply With Quote
Old 10-03-2012, 07:58 AM   PM User | #2
davidjones1990
New Coder

 
Join Date: Sep 2011
Posts: 22
Thanks: 0
Thanked 3 Times in 3 Posts
davidjones1990 is an unknown quantity at this point
You could get rid of that whole IF statement in the form and use a placeholder. For example:

Code:
<input class="searchfield" type="text" name="query" placeholder="Type your ingredients..." value="<?php echo $data['query']; />
This should display your message in the field but not actually POST it if the form is submitted.
davidjones1990 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:06 AM.


Advertisement
Log in to turn off these ads.