public function postNewRun($name) { // Validate that this user can post the run // AKA that they own the shoe // Then POST it $run_date = $_POST['run_date']; $run_miles = floatval($_POST['run_miles']); $shoe_id = $_POST['shoe_id']; $run = new Run(); $run->run_date = $run_date; $run->miles = $run_miles; $run->user_id = Auth::user()->id; $run->shoe_id = $shoe_id; if ($run->save()) { return 1; } else { return 0; } }
<?php define(MAIN_PATH, realpath('.')); include_once MAIN_PATH . '/init.php'; echo render_header(); $user = User::getLoggedIn(); if (!$user) { echo render_logged_out_index(); echo render_footer(); exit; } $params = parse_http_args($_POST, array('time', 'miles', 'route', 'date_month', 'date_day', 'date_year', 'publish_to_facebook')); // If the user has added a run, then handle the form post if (!empty($params['miles'])) { $run = new Run($user, $params); if (!$run->save()) { echo render_error('Something went wrong while saving the run.'); } else { $success = 'Added a new run!'; // This will only be true if the checkbox on the previous page was checked // The feed_loading div will be killed by JS that runs once the feed form // is generated (since it can sometimes take a second or two) if ($params['publish_to_facebook']) { register_feed_form_js($run); $success .= '<div id="feed_loading">Publishing to Facebook... ' . '<img src="http://static.ak.fbcdn.net/images/upload_progress.gif?0:25923" /></div>'; } echo render_success($success); } } // Show the basic add run form on the home page echo '<div class="clearfix">';