Questions & answers

Hi,
I have 2 tables: questions & answers.
Each question has 4 answers (only one is the correct). I need to know the easiest way to edit those answers. Since Im using simple models, I dont want to have one page for questions and another page for answers because it can be a bit complicated for my clients to manage. I was thinking having the answer's textboxes right on the 'create' page in the Questions module, or some sort of popup to add/remove these answers.
Best way to do this?
Please advice.
Thanks!!

Comments

  • edited 11:24AM
    You can alter your questions_model form_fields method to include the answers in the edit form, and then use an on_after_save hook too process the answers back to the answers model.

    To get the answers of your question, you can use the Questions_model::form_fields() method's first parameter passed to it ($values), which I'm assuming will have the question's id value if you are editing (an no value if it's new). This can then be used to query the answers_model:
    if (!empty($values['id'])) $answers = $CI->answers_model->find_all(array('questions_id' => $values['id']));
    Does that make sense?
  • edited 11:24AM
    Ok, ill try that. :)
  • edited 11:24AM
    If I add a custom field on form_fields(), then on on_after_save($values), $values doesnt come with any of those custom fields I added. If instead of $values I use $_POST, then I get those values. Any toughts?
  • edited 11:24AM
    The values being returned to the form_fields method are only those pertaining to that model (table), so in your case, you'll probably need to use $_POST. There is also a model property normalized_save_data (e.g. $this->normalized_save_data) but that only gets set on save and is available in on_after_save.
  • edited 11:24AM
    ok thanks, ive used $_POST
Sign In or Register to comment.