Take the 2-minute tour ×

We are working on an application using the CakePHP framework Basically, its a questionnaire application and it has a few dependant questions, i.e. based on a response to a specific question, it needs to show or hide the next one

For e.g. Question: Are you married? Yes/No

If the user selects Yes, then using javascript the next question gets displayed for user input

Question: Spouse's name

Saving this information is fine, but when editing, when populating the form, we would want to be able to display the fields for which user has inputted data - in this case, it needs to show the field that has the spouse's name

Since by default we are hiding the spouse name field, when editing, it doesn’t display the field, even though there is a value to it

Is there some way that CakePHP can handle this or does it require us to write some javascript to take care of this?

Thanks in advance.

share|improve this question
I don't understand. Are you doing the editing and the question answering on the same page? –  JohnP May 3 '11 at 10:08
Basically, this will be a simple form. Where the users can add the data to DB. The form contains the question and the answers will be stored. We are using same page for edit as well. So how to manage the hide and show functionality for ADD/EDIT using cakephp. –  user599531 May 3 '11 at 10:23
so why not just do a check before displaying? If the field isn't empty, just show the input? –  JohnP May 3 '11 at 10:34
Thanks John. Right now we have two plans and what you are telling is one among them. But is there anything in built with CakePHP? So that our code will be optimized and we can reuse in other pages as well. –  user599531 May 3 '11 at 10:59
@user599531 hard to say, I'm still not sure I understand you fully. But doing a check and showing if required is the way to go I think –  JohnP May 3 '11 at 11:13
add comment

1 Answer

CakePHP does not manage this for you. While CakePHP is very powerful and a great framework, it will not write this kind of logic for you. You must write it.

I would suggest making the EDIT screen different from the ADD screen. Build the list of values from the database and display the fields that have values (and include any empty fields that should require values).

Keep in mind reusable does not necessarily mean that all CRUD actions fit into the same view.

share|improve this answer
Thanks for the comment. –  user599531 May 4 '11 at 6:34
add comment

Your Answer


