<?php //we need to display all available records $to_display = Status::find_all(); //loop through all items foreach ($to_display as $value) { echo "<option value=\"" . $value->status_wk . "\""; echo ">" . $value->name . "</option>"; } ?> </select></div> Age: <br><div class="form-group"><input type="text" name="age" class="form-control" value="0"></div> Weight: <br><div class="form-group"><input type="text" name="weight" class="form-control" value="0.0"></div> Vaccination(s): <br> <?php //we need to display all available records $to_display = Vaccination::find_all(); //loop through all items foreach ($to_display as $value) { echo " <br><div class=\"form-group center\"><input style=\"margin-left:1.70em;\" type=\"checkbox\" class=\"form-control\" name=\"vaccination[]\" value=\"" . $value->vaccination_wk . "\""; echo "> " . $value->vaccination_name . "</div>"; } ?> Is it Rescued?: <br><div class="form-group"> <input type="radio" name="rescued" value="1"> Yes <input type="radio" name="rescued" value="0" checked> No</div> <div class="form-group"><button type="submit" value="submit" name="submit" class="btn btn-success btn-md btn-block">Submit</button></div> </fieldset></form></section> <?php
//delete all pets that use that vaccination $sql = "DELETE FROM `pet_to_vaccination` WHERE `pet_to_vaccination`.`vaccination_wk` = {$to_delete_key};"; $database->query($sql); //now that no pets are using that vaccine, we delete the record $to_delete = Vaccination::find_by_id($to_delete_key); if ($to_delete->delete()) { $session->message("<strong>" . $to_delete->vaccination_name . "</strong> was deleted successfully."); } else { $session->message("<strong>" . $to_delete->vaccination_name . "</strong> was not deleted successfully.<br />" . $database->last_error); } //redirect back to itself without the ?delete_vaccination_wk in the URL //so the system does not try to delete something again redirect_head(file_name_without_get()); } //get all the vaccinations $all_vaccinations = Vaccination::find_all(); //process the form data if (isset($_POST['submit'])) { //an array to keep track of all changes $changes = array(); //flatten all vaccinations into an associated array //where the keys are the indexes //this makes searching 100% easier $flat_all_vaccinations = array(); foreach ($all_vaccinations as $value) { $flat_all_vaccinations[$value->vaccination_wk] = $value->vaccination_name; } //loop through all POST fields foreach ($_POST as $key => $value) { //exclude the submit and new_vaccination fields if (!in_array($key, array('submit', 'new_vaccination'))) {