⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Where Condition With POST / GET Not Work



mnish
  • profile picture
  • Member

Posted 03 September 2013 - 08:02 AM

I Want to sort my table on the basis of form post but the result display only for minor time after that crud shown 'No Item to display'. Why?
 
My Form is:-
 
<form action="<?php echo base_url(); ?>product1" method="post" name="f1">
        <input type="text" name="product_id" value="" />
        <input type="submit" name="submit" value="submit" />
</form>
 
 
 
And My Function  is:
 
 
function product1()
{
$pid = isset($_POST['product_id'])?$_POST['product_id']:'';
 
$this->load->library('grocery_crud');
$crud = new grocery_CRUD();
$crud->where('product_id',$pid);
$crud->set_table('product_main');
$crud->set_subject('Product');
$crud->fields('product_name','product_id');
 
$crud->required_fields('product_name');
 
$output = $crud->render();
 
$this->load->view('_product_crud', $output);
 
}
 
i am also use 
$pid = $this->input->post('product_id');
or $pid = $_POST['product_id'];
 
when i give static value to $pid it works fine..
 
Where Is the Problem..?
 
 
 Plz Help Me...

 


davidoster
  • profile picture
  • Member

Posted 04 September 2013 - 02:38 AM

I don't think it will work like this, having a form where the grid (listing) is.

If you really need to do that use either of the following :

 

1. create two separate views and on one load your form and on the other the crud. call both views from one controller function

2. ajaxify the form

3. make two differenet controller functions, one for the host one for the crud. the host will contain the form and upon submit will pass the $pid to the other crud function. make sure on this crud function you use the http://www.grocerycrud.com/documentation/options_functions/set_crud_url_path . Obviously you will need to make a composite (combined) view 

 

 Well In general this is not a Grocery CRUD issue. It is an MVC design -  architecture topic. Good luck.


mnish
  • profile picture
  • Member

Posted 06 September 2013 - 17:51 PM

 Well In general this is not a Grocery CRUD issue. It is an MVC design -  architecture topic. Good luck.

 

My Friend Davidoster Plz don't mind i think this is the grocery crud issue because  if we send post data to function where we use grocery crud library.

if we change form post value to static value(i.e. where('product_id',4)) crud works fine but if use form post value into where clause the clause not work so i think this the the GC issue.

By the way you are Grocery CRUD Ninja so you are right... :)


davidoster
  • profile picture
  • Member

Posted 06 September 2013 - 22:03 PM

[member=mnish] Ninja doesn't mean anything!

And who's right it doesn't matter. What matters is to help each other here!

And by the way you said it yourself, when sending a static value on the where it works. Doesn't this mean that GC works also?

So check the value you send from the form!


Amit Shah
  • profile picture
  • Member

Posted 07 September 2013 - 15:47 PM

Well Mr. mnish,

 

You can verify the value reaching out to the code / function by many ways...

1 - u can use firefox with firebug addon

2 - u can print_r($_POST)

 

First - verify what id it is being used to pass the value to the function.. and is it really being passed in or not.


mnish
  • profile picture
  • Member

Posted 07 September 2013 - 16:24 PM

Thanx Mr Amit For giving me some beautiful tips but I have already tried both option.

 

Can you giving an example where we use $crud->where('field_name',$this->input->post('post_variable_name')); thanx in advance.


davidoster
  • profile picture
  • Member

Posted 07 September 2013 - 22:00 PM

Thanx Mr Amit For giving me some beautiful tips but I have already tried both option.

 

Can you giving an example where we use $crud->where('field_name',$this->input->post('post_variable_name')); thanx in advance.

 

As the documentation says, http://www.grocerycrud.com/documentation/options_functions/where

check CI's where since it is exactly the same.


timenz
  • profile picture
  • Member

Posted 01 January 2015 - 11:33 AM

affect me also, it's happen because when we load page, it's receive post/get parameter, then after loading grocery crud refresh the result by run ajax request (index/ajax_list),

the problem is, this ajax request don't have our post/get data, so the result reseted as same as without post/get data.