-
acheng16
Junior Member
-
Posts: 16
Threads: 3
Joined: Jan 2016
Reputation:
0
So I have a view called select_dates.php and it takes in POST data (start date, end date, and product ID). Once you press submit
$this->load->private_view('reports/edit', $data);
which will load a view that has the report based on the POST data given. However this view(reports/edit) also has a form at the top which can ask for these same 3 POST data in select_dates.php. However once I press submit here the data isn't getting posted at all. Any thoughts or ideas?
-
acheng16
Junior Member
-
Posts: 16
Threads: 3
Joined: Jan 2016
Reputation:
0
(02-25-2016, 12:22 PM)RobertSF Wrote: Yes, I'm not really picturing it. If you load a view and pass it an array ($data), and that view itself loads a view, you don't need to pass the array to that second view. Like Wouter60 suggest, post some code, and make sure to put it in a PHP code block.
National method in controller
PHP Code: public function national(){ $this->head->add('js', GLOBAL_LIB . '/chartjs/ChartNew.js'); log_message("debug", "At start of National Report"); $this->load->helper("form"); if( $this->input->post() ): log_message("debug", "data Product ID is: " + $data['product_id']); if($data['product_id'] == NULL) { $data['product_id'] = $this->input->post('product_id'); } $data['start_date'] = $this->input->post('start_date'); $data['end_date'] = $this->input->post('end_date'); $this->load->model('campaigns_model'); $this->campaigns_model->product_id = $data['product_id']; $campaigns = $this->campaigns_model->load(false,false,true);
if( empty( $campaigns ) ): $data['report_description'] = 'Select your program to display the overview of national statistics for the selected program.'; $this->session->set_userdata(array('status_message' => 'No campaigns selected.', 'status_type' => 'bad')); //$this->load->private_view('reports/select_product'); redirect('private/reports/national'); else:
$this->load->model('reports_model'); $report_data = $this->reports_model->get_campaign_report($campaigns, $data['start_date'], $data['end_date']);
list( $data['campaign'], $data['product'], $data['questions'], $data['screenings'], $data['risk_levels'], $data['screening_days'], $data['no_misuse'], $data['in_recovery']$
$data['report_description'] = 'Below is the overview of national statistics for the selected program.'; $data['report_type'] = 'national'; $data['report_title'] = $data['product']->title; $data['item_type'] = strtolower(str_replace(' ','_',$data['product']->title)); $data['item_id'] = strtolower(str_replace(' ','_',$data['product']->title));
// dyanmic js for charts $data['js'] = $this->load->view('private/reports/edit.js.php', $data, true);
$report_csv_data = $this->reports_model->get_campaign_csv( $data['screenings'], $data['product']->product_id ); $csv_path = REPORT_FILE_PATH . '/national_' . $data['item_type'] . '/' . $data['item_type'] . '_' . $data['item_id'] . '.csv'; $this->load->library('csv_library'); $this->csv_library->create_csv($csv_path, $report_csv_data, $data['product']->product_id); $this->load->private_view('reports/edit', $data); log_message("debug","At end of National"); endif; else: $data['products'][1] = 'ScreenU Alcohol Campaigns'; $data['products'][2] = 'ScreenU Rx Campaigns'; $this->load->private_view('reports/select_product', $data); endif; }
edit.php in controller
PHP Code: public function edit($campaign_id = '') { $this->head->add('css',GLOBAL_LIB . '/hopscotch/hopscotch.min.css'); $this->head->add('js',GLOBAL_LIB . '/hopscotch/hopscotch.min.js');
$this->head->add('js', GLOBAL_LIB . '/chartjs/ChartNew.js'); log_message("debug", "In Edit"); $this->load->helper('form'); if ($this->input->post()) { log_message("debug", "In Edit"); $data['start_date'] = $this->input->post('start_date'); $data['end_date'] = $this->input->post('end_date'); $data['product_id'] = "2"; }
$data['reports_edit_first_visit'] = ( $this->user_model->get_user_meta($this->auth_lib->user_id(),'reports_edit_first_visit') == '' ? true : false ); // its our first time here! if( $data['reports_edit_first_visit'] ){ $this->user_model->update_user_meta($this->auth_lib->user_id(),'reports_edit_first_visit',date('Y-m-d H:i:s')); } $this->load->model('reports_model'); if ($data['campaigns'] == NULL) { $data['report_title'] = $data['campaign']->title; $report_data = $this->reports_model->get_campaign_report($campaign_id, $data['start_date'], $data['end_date']); }else { $data['report_title'] = $data['product']->title; $report_data = $this->reports_model->get_campaign_report($data['campaigns'], $data['start_date'], $data['end_date']); } list( $data['campaign'], $data['product'], $data['questions'], $data['screenings'], $data['risk_levels'], $data['screening_days'], $data['no_misuse'], $data['in_recovery'] ) = $report_dat$
$data['report_description'] = 'The following is an overview of all the responses for a specific campaign.'; $data['report_type'] = 'campaign'; $data['item_type'] = 'campaign'; $data['item_id'] = $data['campaign']->campaign_id; // dyanmic js for charts $data['js'] = $this->load->view('private/reports/edit.js.php', $data, true); /* // generate pdf $this->load->library('tcpdf_library'); $html_content = $this->load->private_pdf_view('reports/campaign_pdf', $data);
$this->tcpdf_library->create_pdf(REPORT_FILE_PATH . '/campaign_' . $data['campaign']->campaign_id .'/campaign_' . $data['campaign']->campaign_id .'.pdf', $html_content, 'ScreenU Campaign $ */ // generate csv $report_csv_data = $this->reports_model->get_campaign_csv($data['screenings'], $data['product']->product_id ); $this->load->library('csv_library'); $this->csv_library->create_csv(REPORT_FILE_PATH . '/campaign_' . $campaign_id . '/campaign_' . $campaign_id . '.csv', $report_csv_data, $data['product']->product_id ); $this->load->private_view('reports/edit', $data); }
Select_Product.php (uses National method)
PHP Code: <script type="text/javascript"> <?php echo $js; ?> </script> <div class="content-header"> <h1>Reporting</h1> </div> <div class="content"> <input type="hidden" name="reports_campus_first_visit" id="reports_campus_first_visit" value="<?php echo ( $reports_campus_first_visit ? '1' : '0' ); ?>" /> <p>The following Campus Report is an overview of all the responses for a specific campaign.</p>
<hr />
<div id="welcome" class="hopscotch-item"> <h3>Select a Program and a Date Range</h3>
<div class="box"> <div class="wrapper"> <form action="" method="post" id="product_form"> <div class="row"> <div class="col span_4"> <select name="product_id"> <option value="">- Select a Program -</option> <?php foreach( $products as $kproduct => $product ): ?> <option value="<?php echo $kproduct; ?>"><?php echo $product; ?></option> <?php endforeach; ?> </select> </div> <div class="col span_3"> <input type="text" class="datepicker" name="start_date" placeholder="Start Date" /> </div> <div class="col span_1"> </div> <div class="col span_3"> <input type="text" class="datepicker" name="end_date" placeholder="End Date" /> </div> </div> <div class="row"> <div class="col span_12"> <input type="submit" class="outline-button" value="See Report" /> </div> </div> </form> </div> </div> </div> </div>
Edit.php View
PHP Code: <script type="text/javascript"> <?php echo $js; ?> </script> <div class="content-header"> <h1>Reporting</h1> </div> <div class="content"> <input type="hidden" name="reports_edit_first_visit" id="reports_edit_first_visit" value="<?php echo ( $reports_edit_first_visit ? '1' : '0' ); ?>" /> <p class="no-print"><?php echo $report_description; ?></p>
<div class="box"> <div class="wrapper"> <form action="" method="post" id="date_picker_form"> <div class="row"> <h5>To view a report for a specific date range, please enter the dates below. To see the report without date parameters, please press “see report.”</h5> </div> </br> <div class="row"> <div class="col span_3"> <input type="text" value="<?php echo set_value('start_date'); ?>" class="datepicker" name="start_date" placeholder="Start Date" /> </div> <div class="col span_1"> </div> <div class="col span_3"> <input type="text" value="<?php echo set_value('end_date'); ?>" class="datepicker" name="end_date" placeholder="End Date" /> </div> </div> <div class="row"> <div class="col span_12"> <input type="submit" class="outline-button" value="See Report" /> </div> </div> </form> </div> </div>
<?php /* DEBUG echo 'report type: ' . $report_type . '<br />'; echo 'item type: ' . $item_type . '<br />'; echo 'item id: ' . $item_id . '<br />'; */ ?> <hr />
<h3>Data for <?php echo $report_title; ?> <span><?php echo count($screenings); ?> Responses</span></h3> <?php if( isset( $date_range ) ): ?> <p><?php echo $date_range; ?></p> <?php endif; ?>
<div id="welcome" class="hopscotch-item"> <div class="box plain"> <div class="head"> <h3><a href="#" class="expandable" rel="in_recovery">Data For Those In Recovery</a></h3> </div> <div class="expandable" id="in_recovery"> <div class="row"> <div class="expandable" id="in_recovery"> <div class="row"> <div class="col span_12"> <div class="minidonuts"> <div class="minidonut_wrapper"> <canvas id="in_recovery_chart" class="horiz_chart" height="150" width="150"></canvas> <span class="download_image" rel="in_recovery_chart" title="Download this graphic"><i class="fa fa-download"></i></span> </div> </div> </div> </div> <br class="clear" /> <div class="question_details"> <div class="head"> <h4><a href="#" class="expandable" rel="in_recovery_gender_details">Gender</a></h4> </div> <div class="expandable" id="in_recovery_gender_details"> <canvas id="in_recovery_genders_chart" class="horiz_chart" height="150" width="150"></canvas> <div style="display: none;"><canvas id="in_recovery_genders_chart_data_only" class="horiz_chart" height="150" width="150"></canvas></div> <span class="download_image" rel="in_recovery_genders_chart" title="Download this graphic"><i class="fa fa-download"></i></span> </div> </div> <div class="question_details"> <div class="head"> <h4><a href="#" class="expandable" rel="in_recovery_class_rank_details">Class Rank</a></h4> </div> <div class="expandable" id="in_recovery_class_rank_details"> <canvas id="in_recovery_class_ranks_chart" class="horiz_chart" height="100" width="100"></canvas> <div style="display: none;"><canvas id="in_recovery_class_ranks_chart_data_only" class="horiz_chart" height="150" width="150"></canvas></div> <span class="download_image" rel="in_recovery_class_ranks_chart" title="Download this graphic"><i class="fa fa-download"></i></span> </div> </div> <div class="question_details"> <div class="head"> <h4><a href="#" class="expandable" rel="in_recovery_age_details">Age</a></h4> </div> <div class="expandable" id="in_recovery_age_details"> <div style="display: none;"><canvas id="in_recovery_ages_chart" class="horiz_chart" height="100" width="100"></canvas></div> <canvas id="in_recovery_ages_chart_data_only" class="horiz_chart" height="100" width="100"></canvas> <span class="download_image" rel="in_recovery_ages_chart_data_only" title="Download this graphic"><i class="fa fa-download"></i></span> </div> </div> </div> </div> <div class="box plain"> <div class="head"> <h3><a href="#" class="expandable" rel="no_misuse">Data for those reporting no <?php if ($product->product_id == '1') { echo ""; } elseif ($product->product_id == '2') { echo "mis"; } else { echo ""; } ?>use in past 12 months</a></h3> </div> <div class="expandable" id="no_misuse"> ... so on so forth
-
RobertSF
Member
-
Posts: 239
Threads: 7
Joined: Oct 2014
Reputation:
16
03-03-2016, 06:59 PM
(This post was last modified: 03-03-2016, 07:02 PM by RobertSF.)
(02-24-2016, 03:52 PM)acheng16 Wrote: So I have a view called select_dates.php and it takes in POST data (start date, end date, and product ID). Once you press submit
$this->load->private_view('reports/edit', $data);
which will load a view that has the report based on the POST data given. However this view(reports/edit) also has a form at the top which can ask for these same 3 POST data in select_dates.php. However once I press submit here the data isn't getting posted at all. Any thoughts or ideas?
Where is select_dates.php and where is it called from? The code you included doesn't have it.
Also, now that I notice, what is $this->load->private_view? Is private_view an extension of the loader library? Could it be that it has the error where data passed to a view is not available in all views? Check out this simple example.
controller home.php
PHP Code: public function index() { $user_id = $this->session->userdata('user_id'); $data = array ( 'user_login' => $this->session->userdata('user_login'), 'menu' => array ( 'Lists' => 'glist', 'Memberships' => 'glist/membership', 'Wish List' => 'gifts/wishlist', 'Gifts' => 'gifts/commitlist', 'Logout' => 'user/logout' ) ); $this->load->view('home_view', $data); } }
view home_view.php
PHP Code: <?php $this->load->view('header'); ?>
<div id="content">
<!-- content goes here -->
</div><!-- content -->
<?php $this->load->view('footer'); ?>
view footer.php
PHP Code: <div id="sidebar"> <?php if ($this->session->userdata('user_id')) : ?> <h2>User</h2> <p><?php echo $this->session->userdata('user_login') ?></p> <?php endif; ?> <dt> <?php foreach ($menu as $name => $link) : ?> <dl><a href="<?php echo $link ?>"><?php echo $name ?></a></dl> <?php endforeach; ?> </dt> </div><!-- sidebar -->
</div><!-- page -->
</body> </html>
In the home controller, I load the user id and the menu into $data and then I go $this->load->view('home_view', $data);
So far, so good. The view home_view receives $data and converts its elements into variable. Then the view home_view calls the view footer.php. Note that it does not send it any data. It won't need to. When CI loads the view footer.php, the variables extracted from the $data are already available without having to do anything.
I could also have called all views from the controller instead of the controller calling one view that then calls other views. It works the same either way. So I'm suspecting private_view.
Hey, don't work without a PHP debugger. Several free IDEs have this features built in. Two are NetBeans and CodeLobster. Without a debugger, it's like you're driving with a blindfold on -- you are going to crash!
-
Wouter60
Posting Freak
-
Posts: 851
Threads: 38
Joined: Feb 2015
Reputation:
77
03-05-2016, 09:04 AM
(This post was last modified: 03-05-2016, 09:04 AM by Wouter60.)
In your edit.php (view) you are generating a form with these attributes:
Code: <form action="" method="post" id="date_picker_form">
Because of the action="", the input is posted to the same url that was used to call the form.
Maybe I'm wrong, but as far as I can see, the form is generated from the National method first. If you submit your form, the data is posted to the National method again, and I think that's where you are going wrong.
-
acheng16
Junior Member
-
Posts: 16
Threads: 3
Joined: Jan 2016
Reputation:
0
(03-05-2016, 09:04 AM)Wouter60 Wrote: In your edit.php (view) you are generating a form with these attributes:
Code: <form action="" method="post" id="date_picker_form">
Because of the action="", the input is posted to the same url that was used to call the form.
Maybe I'm wrong, but as far as I can see, the form is generated from the National method first. If you submit your form, the data is posted to the National method again, and I think that's where you are going wrong.
I think that is the case. How would you post the data to the edit method view? if its possible! Thanks Wouter!
|