clickpass Posted October 31, 2016 Share Posted October 31, 2016 Hi everyone! I have managed to build a little form where the entries are saved as a page. That works nice. My problem is that I need to use several forms for several diffrent questions, while the answer to each question is going to be listed below. For assorting the answers to their related questions I have made child pages for each question and gave them different related templates. The POST page should be saved under the parent, which is one child of the question siblings, and it should be given the particular template related to the child page. (It even worked fine one time before I made some changes). The problem is that the generated page from the form is then saved under all of the question siblings as a child. Where is the problem? I have six pages with six different templates. The templates all are holding the same fields. On submit a child page, basing on the template(s) is generated but unfortunately saved as a child under all of the six question pages. I want to save each answer as a child page of the related question page, but only there. What goes wrong? I am using Ryan's proposed snippet for such task, which I am greatly thankful for. Still in development and not much changed it looks like this: <?php // form was submitted so we process the form if($input->post->submit) { // create a new Page instance $p = new Page(); // set the template and parent (required) $p->template = $templates->get("kommentare_zitat_1"); $p->parent = $pages->get("/comments/kommentare_zitat_1/"); // populate the page's fields with sanitized data // the page will sanitize it's own data, but this way no assumptions are made $p->kommentar = $sanitizer->textarea($input->post->kommentar); $p->namez = $sanitizer->text($input->post->namez); $p->profession = $sanitizer->text($input->post->profession); // PW2 requires a unique name field for pages with the same parent // make the name unique by combining the current timestamp with title $p->name = $sanitizer->pageName(time() . $p->title); $p->save(); header("Refresh:0"); } else { // no form submitted, so render the form include("./comments-form.inc"); } ?> The template "kommentare_zitat_1" also exists as "kommentare_zitat_2" etc. The parent page "/comments/kommentare_zitat_1/" has siblings until "/coments/kommentare_zitat_6/". Now any time I am submitting an answer to one question/page, six pages are saved, each question sibling gets one. Might there be an easy solution? I don't know why this is not functioning anymore. Thx, Daniel Link to comment Share on other sites More sharing options...
clickpass Posted October 31, 2016 Author Share Posted October 31, 2016 The point seems to be that a copy of each page is saved under all siblings. They are copies, but why? When I say save a child page under "/comments/kommentare_zitat_1", how can there be 5 other copies under the siblings? Link to comment Share on other sites More sharing options...
BitPoet Posted October 31, 2016 Share Posted October 31, 2016 Your description is a bit hard to understand without a visual overview, but my suspicion (correct me if I'm wrong) is that you're building one complete form on the parent page from all child (question) pages. This would mean that the if($input->post->submit) part is executed in each included template every time you submit the form. 3 Link to comment Share on other sites More sharing options...
clickpass Posted October 31, 2016 Author Share Posted October 31, 2016 Yes, BitPoet, I know it sounds puzzling. But your answer is as useful as simple. Thank you! I just had to add some names to my submits and get what I need now. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now