Welcome Guest, Not a member yet? Register   Sign In
How to find records in a form

Hello everybody

Im facing the following problem:

Suppose I have a form : ORDER

Inside this form I can put many items : PRODUCTS

Suppose I dont know the product ID, so I would like search the product table by name or referenca

I would like do click a button, open another window where I could type the name of the product, and all products whose began with that initial characters woul appear, so I could select one of them, the search window would close and return the selected data do the first form

Any suggestions?

Thanks a lot

You're going to have to use javascript to do this. Anything dynamic on the user side is going to be javascript. I use jquery for all my javascript(because it's quicker), so that's how my example is going to be.

Step 1: Use javascript to open a new window in the page that has the form
<a href="#" id="product_search">Search Products</a>
    return false

Step 2: In /url/to/searchpage, make it search the products listings like normal. Each product will have a link to add.

Step 3: In the link to add, grab all the data you're going to populate the form with. Make sure it is a single level array. Use json_encode to convert it to javascript and print it out.

Here is an example of the page that adds the item.

//Code to get the data here
$data = json_encode($this->db->row_array());
        $(document).ready(function) {
            var data = &lt;?=$data?&gt;;
            for (key in data) { Loop through the array.  I'm going to pretend your form fields are named the same as the database entry

That will populate the opening window with your data.

Theme © iAndrew 2016 - Forum software by © MyBB