Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: Array value.

  1. #1
    New to the CF scene
    Join Date
    Oct 2012
    Thanked 0 Times in 0 Posts

    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:

        <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" />
    Then handler.php looks like this:

    <?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? <(^.^)>!

  2. #2
    New Coder
    Join Date
    Sep 2011
    Thanked 7 Times in 7 Posts
    You could get rid of that whole IF statement in the form and use a placeholder. For example:

    <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.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts