verdeandrea Posted November 12, 2015 Share Posted November 12, 2015 Hi guys, this is what i'm trying to do. I have a template with a textarea and a repeater field. When I create a page i want to paste some text copied from excel and the when i save the page i want to cycle through that text and create new repeaters item in the same page according to it. I'm just starting with hooks and stuff so i'm doing something wrong caso I alway get this error "Call to a member function getNew() on null" Here is what I've written in my module public function init() { $this->pages->addHookAfter('Pages::saveReady', $this, 'afterRankSave'); } public function afterRankSave($event) { $page = $event->arguments[0]; // excel_paste is the textarea field where i paste from excel if($page->template == 'group_rank' && $page->excel_paste !== '') { $this->message("You pasted an excel"); $rows = explode("\n", $page->excel_paste); foreach($rows as $idx => $row) { $row = explode( "\t", $row ); $this->message($row); $rank_position = $page->group_rank_user_repeater->getNew(); $rank_position->group_rank_user_name = $this->sanitizer->text($row[0]); $rank_position->group_rank_user_concessionaria = $this->sanitizer->text($row[1]); $rank_position->group_rank_user_points = $row[2]; if($row[3] == 1) { $rank_position->gruppo_rank_user_winner = 1; }; } $page->excel_paste = ''; } } I need to empty the "excel_paste" fielsd, otherwise it get in an infinite loop. I'm not sure on what hook I should use. I not sure about the logic of this stuff. Thank you! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now