Problems, need help? Have a tip or advice? Post it here.
17 posts Page 1 of 2
Hello I might oversee something. Hopefully someone could point me towards the right direction.

I want to do a quiz where the Admin can change the Questions and the possible Answers and the Visitors can do the quiz and submit a form with the correct Answer. Thats easy!

But what can I do with the submitted form? It seems like couchcms can only send the form via Email. Is there a way to see the submitted data in de Admin Backend?

Ok I know there are DataBound Forms. But do they suite my needs? I dont know how to place configurable inputfields in DataBound Forms i started like this:

Code: Select all
<?php require_once( 'couch/cms.php' ); ?>
<cms:template title='form' clonable='1'>
    <cms:editable name='participant_name' required='1' type='text' />
    <cms:editable name='answer' required='1' type='dropdown'
        opt_values=' possible answers=- | Ans 1 | Ans 2 | Ans 3 | Ans 4 ' 
       //1. how can the Admin change those possible Answers in the Backend?
    />
</cms:template>

<cms:form masterpage=k_template_name mode='create' enctype='multipart/form-data' method='post' anchor='0'>

  <cms:if k_success >
    <cms:db_persist_form _invalidate_cache='0' _auto_title='1'/>     
    <cms:set_flash name='submit_success' value='1' />
    <cms:redirect k_page_link />
  </cms:if>
  <p>What is the Answer to this Question? <p>
  //2. and how can i make this <p>-Tag editable from the Admin-Backend?

  <!--
  3. of course this is noch going to work but i tried all kind of stuff:
  <cms:editable type="richtext" name="aQuestion">
    <p>Second Question here?</p>
  </cms:editable>
  -->

  <cms:input name="participant_name" type="bound" />
  <cms:input name="answer" type="bound" />

  <cms:if "<cms:not submit_success />" >
    <button type="submit">Submit Answer</button>
  </cms:if> 

</cms:form>
<?php COUCH::invoke(); ?>


Thank you for any Help!

kind regards

Olaf
Hi Olaf :)

While we can certainly use DataBound forms to create such Q&A site, can you please take a look at the Poll module (viewtopic.php?f=5&t=8133) and see if that would suffice?

If not, I'll request you to put aside the solution for a moment and post here only the problem i.e. how exactly will your site work. Will the questions be drawn from a pool? How many questions will be offered to a visitor etc.

Please do not worry about what code to use at this moment. Just concentrate on what needs to be done.

Thanks.
Hello KK,
Thank you for that quick and helpful answer. I think the Poll plugin can be useful for me. But its not what i really need because you can only send predefined answers without any context.

I need to send real formdata to the backend.

Here is a quick mockup of what i try to achieve. That image will make it totally clear.
Is there a better solution than starting from the poll plugin?

Thank you!

mockup.png
mockup
mockup.png (93.72 KiB) Viewed 2635 times
Any help would be appreciated :(
Apologies for the delay, @olaf.

May I ask you just one more question?
Going by your screenshots, there is one quiz question (with its options) and then there are user-submitted answers to that question. Fine.

What happens when the admin decides to put in a new question?
He is surely not going to edit the original question as that would invalidate the existing replies.

I think, he'll create a brand-new question (with its set of options) and then replace the original one with it on the front-end (in the back-end, both questions will remain).

Any user-submitted replies will now pertain to the new question and so should appear only with it (and not the first question).

Do you see my point?
Please let me know if I'm wrong in my assumptions.

Thanks.
In the future i would maybe want to add more than one question per Quiz. But for now it would be enough if there is just one Question with options per "couchcms - installation".

Step by Step.

Thanks and no reason for apologies
OK, so that should be fairly straightforward.

Please give me just a little time. I'll create the solution for you.

Thanks.
Wow. Thank you. Never heard a answer like that in a Forum.

I am looking forward for your answer.

best Regards

Olaf
Hi Olaf,

Here is the promised solution.
It makes use of two templates -
1. 'quiz.php' for entering the question and its answers
2. 'results.php' clonable template for recording the submitted results.

quiz.php:
Code: Select all
<?php require_once( 'couch/cms.php' ); ?>
<cms:template>

    <cms:editable name='question' label='Please enter a question for your quiz' type='text' />
   
    <cms:repeatable name='answers' label='Answers'>
        <cms:editable name='answer' type='text' />
    </cms:repeatable>
   
</cms:template>


<?php COUCH::invoke(); ?>   

Untitled-1.gif
Untitled-1.gif (12.09 KiB) Viewed 2592 times


results.php:
Code: Select all
<?php require_once( 'couch/cms.php' ); ?>
<cms:template clonable='1'>
    <cms:editable name='participant_name' required='1' type='text' />
    <cms:editable name='participant_email' required='1' type='text' />
    <cms:editable name='participant_response' required='1' type='text' />
</cms:template>


<!-- get values from quiz.php for use in this page below -->
<cms:pages masterpage='quiz.php' limit='1'>
    <cms:capture into='my_answer_values' 'global'>
        <cms:show_repeatable 'answers' >
           | <cms:show answer  />
        </cms:show_repeatable>
    </cms:capture>
   
    <cms:set my_question=question 'global' />
   
</cms:pages>


<cms:set submit_success="<cms:get_flash 'submit_success' />" />
<cms:if submit_success >
    <h4>Success: Your response has been submitted.</h4>
</cms:if> 

<h2>Question:</h2>
<h4><cms:show my_question /></h4>
   
<cms:form masterpage=k_template_name mode='create' enctype='multipart/form-data' method='post' anchor='0'>
    <cms:if k_success >
        <cms:db_persist_form
            _invalidate_cache='0'
            _auto_title='1'
           
            participant_response=frm_answer
        />     
       
        <cms:if k_success >
            <cms:set_flash name='submit_success' value='1' />
            <cms:redirect k_page_link />
        </cms:if>
    </cms:if>

    <cms:if k_error>
        <cms:each k_error >
            <br><cms:show item />
        </cms:each>
    </cms:if>
   
    <label for="answer">Select Answer</label>
    <cms:input
        type="radio"
        name="answer"
        opt_values=my_answer_values
    /><br/>
   
    <label for="participant_name">Name</label>
    <cms:input name="participant_name" type="bound" style="width: 300px;" /><br/>
   
    <label for="participant_email">E-Mail</label>
    <cms:input name="participant_email" type="bound" style="width: 300px;" /><br/>
   
    <button type="submit">Submit Answer</button>
</cms:form>

<?php COUCH::invoke(); ?>   

Hope this helps.
Wow you are crazy! Thanks for the solution. I will definitely use this in my next project soon.
17 posts Page 1 of 2
cron