⚠ 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

Save and Save and go back to list borked when adding.



Chris Bruner
  • profile picture
  • Member

Posted 11 October 2013 - 08:54 AM

I've no idea what is causing this. It claims that the save worked, but there is no new data.  I turned on the code igniter profiler, and I can see lots of selects but nothing adding to the database.

Weird thing is, if I edit an existing record it works fine. Only problem is when adding a new record.

 public function index() {
                                // redirect if user isn't logged in
                if (!$this->ion_auth->logged_in()) {
                        redirect('/');
                }

                $crud = new grocery_CRUD();
                $crud->where('user_id',$this->user->id);
                $crud->set_table('New_userStocks')
                                                ->fields('company_id','boughtDate','boughtPrice','shares','boughtCommission',
                                                                'soldDate','soldPrice','soldCommission','scInspired', 'userNotes','expert_id')
                                                ->set_subject('Investment')
                                                ->columns('company_id','boughtDate','userNotes','boughtPrice','shares','boughtCommission','soldDate','soldPrice','soldCommission','profit')
                                                ->display_as('company_id','Company')
                                                ->display_as('boughtDate','Bought')
                                ->display_as('boughtPrice','Purchase Price')
                                ->display_as('shares','Shares')
                                ->display_as('boughtCommission','Bought Commission Cost')
                                ->display_as('soldCommission','Selling Commission Cost')
                                ->display_as('soldDate','Sold')
                                ->display_as('soldPrice','Sale<br>or<br>Current<br>Price')
                                ->callback_column('soldPrice',array($this,'_callback_SoldPrice'))
                                ->field_type('userNotes','text')
                                ->callback_column('profit',array($this,'_callback_Profit'))
                                                ->display_as('scInspired','StockChase Inspired')
                                                ->display_as('userNotes','Notes')
                                                ->callback_column($this->unique_field_name('company_id'),array($this,'_callback_company_url'))
                                        ->callback_column('boughtDate',array($this,'_callback_boughtDate'))
                                        ->callback_column('userNotes',array($this,'_callback_Price'))
                                                ->set_relation('company_id','New_company','{symbol} {name}')
                                                ->set_relation('expert_id','New_expert','{name}<!--{id}-->');
                if ($crud->getState() == 'list') {
                        $crud->display_as('boughtCommission','+Cost')
                        ->display_as('soldCommission','+Cost');
                }

                $crud->field_type('scInspired','true_false',array('No','Yes'));

                $crud->field_type('boughtDate','date');
                $crud->required_fields('company_id');
                $detailoutput = '';
                $table_view = $crud->render();
                $this->template->title('My Portfolio');
                $this->template->build('portfoliog',$table_view);


        //$this->load->view('example.php',$crud->render());//<input id='field-boughtDate' name='boughtDate' type='text' value='' maxlength='10' class='datepicker-input' />

                }

Can you point me in a direction to look please?


Amit Shah
  • profile picture
  • Member

Posted 11 October 2013 - 11:43 AM

you should be able to track in as where is the issue in firebug - where on click of the save (not save and go back) - if there is an issue - where is the issue and what is the issue like


Chris Bruner
  • profile picture
  • Member

Posted 13 October 2013 - 06:12 AM

I'm not familiar with firebug so maybe I'm not using it right. But there appears to be no issue. It sits there happily saying that the data has been saved, yet it hasn't.


Amit Shah
  • profile picture
  • Member

Posted 13 October 2013 - 08:27 AM

Well i will recommend you install and activate firebug in firefox .. and just have a basic know how as how to use it. There you will be able to see the actual result of the ajax call (the 1 used by GC for insert)


Chris Bruner
  • profile picture
  • Member

Posted 14 October 2013 - 08:15 AM

<form id="crudForm" accept-charset="utf-8" enctype="multipart/form-data" autocomplete="off" method="POST" action="http://www.stockchase1.com/portfolio/index/insert" encoding="multipart/form-data">

bunch of other stuff.

<div class="form-button-box">
<input id="form-button-save" class="btn btn-large" type="submit" value="Save">
</div>

It's probably my ignorance in how grocery works but to me it looks like a normal form/submit, where would the ajax be in this?


Amit Shah
  • profile picture
  • Member

Posted 14 October 2013 - 09:25 AM

Well sir - when you click on the save button - the data is submitted through ajax and not a normal form submit - that is how when u click on the form with validation - it dont have javascript validation - it goes to server - processes the rules and validates the system. And a response from server, if any error - is thrown back to the form and it gets displayed else it gets saved. That is the reason why your data when you click - u get message it is been saved - but you dont find it in backend for some reason. And no regular form submit will be able to show you such message.


Chris Bruner
  • profile picture
  • Member

Posted 14 October 2013 - 17:44 PM

I've been setting breakpoints on every function I can find on the page. Nothing appears to be trapping the Save button.  Give me a hint. Where do I set the bp to trap the save button.


Amit Shah
  • profile picture
  • Member

Posted 14 October 2013 - 21:39 PM

the only trick on it is - use firefox with firebug - u surely will get the solution. When u monitor on the console .. post your save click u willl see the call going to the server. There when u click on the response - u will see the actual output / response coming in


edramirez
  • profile picture
  • Member

Posted 10 November 2013 - 14:53 PM

One of the things to remember in grocerycrud is that you shouldn't put the grocerycrud operation in the index function. The index function should call the function where the grocerycrud operation resides.

 

Regards,

 

Ed Ramirez

 

P.S. Don't forget to click the Like button...  :)


Chris Bruner
  • profile picture
  • Member

Posted 29 December 2013 - 06:09 AM

OK I've just got back to this, and I think I've finally found the problem. the code has:

  $crud->where('user_id',$this->user->id);

which looks up the users info. When adding more user's info to the table, it needs to be added under that users id. Right now it's all getting added as user_id null I suppose.

 

 

 

So how to I insure that the user_id is preserved?


Chris Bruner
  • profile picture
  • Member

Posted 29 December 2013 - 07:15 AM

found it.

   function _callback_insert($post_array)
        {
                $post_array['user_id'] = $this->user->id;
                return $this->db->insert('New_userStocks',$post_array);
        }       

fixed it.