Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8234401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T18:27:44+00:00 2026-06-07T18:27:44+00:00

Project: To create dynamic multi page form that populates the fields in different ways

  • 0

Project: To create dynamic multi page form that populates the fields in different ways depending on various situations.

Context: Using CMSMS and Smarty tags to insert PHP into the requried pages. Each single page of the form is being built using a single smarty

Current Method: Using smarty tags, I am writing large chunks of HTML echoed in heredoc notation. When I reach a part of the form that needs to be dynamically genearted (such as a drop down menu) I escape the heredoc, write the PHP (using standard echo functions to generate the HTML required for that form element) then return to heredoc for more chunks of HTML.

Suspicion: this is inelegant, messy, tedious and just feels wrong.

Request: Any idea of a better way of doing this?

EDIT: An example of a chunk of my current setup, here you can see an initial chunk of static HTML is echoed – (the start of the form, and the first question) then a drop down menu which requires dynamic generation depending on the data that exists in the SESSION variables. After this, the heredoc resumes and echos more static HTML:

echo <<<EOD
<form id="myform" method="post" action="?page=2">
<div class="myform">

<div class="formfield">
    <div class="question"><label for="sv_01">Question?</label> <input type="text" name="sv_01" value="$sv_01" size="10" maxlength="10" /></div>
        <div class="subquestion"><label for="sv_02">What Year?</label>
EOD;
                echo '<select  name="sv_02">';   
                $vars = array(
                '-Year' => 'Year',
                '-2012' => '2012', 
                '-2011' => '2011', 
                '-2010' => '2010', 
                '-2009' => '2009', 
                '-2008' => '2008', 
                '-2007' => '2007', 
                '-2006' => '2006', 
                '-2005' => '2005', 
                'Pre 2005' => 'Pre 2005', 
                );

                foreach($vars as $val => $name){
                    if($_SESSION['sv_02'] == $val){
                        echo '<option value="' . substr($val, 0, 1) . '" selected>' . $name . '</option>';
                    } else {
                        echo '<option value="' . substr($val, 0, 1) . '">' . $name . '</option>';
                    }
                }

                echo '</select></div>';
echo <<<EOD

    <div class="question"><br /> <label for="sv_04">Another question</label> <input type="text" name="sv_04" value="$sv_04" size="10" maxlength="10" />%</div>
        <div class="subquestion"><label for="sv_07">When was the data collected?</label> 
EOD;
                echo '<select  name="sv_07">';   
                $vars = array(
                '-Month' => 'Month',
                '-January' => 'January', 
                '-February' => 'February', 
                '-March' => 'March', 
                '-April' => 'April', 
                '-May' => 'May', 
                '-June' => 'June', 
                '-July' => 'July', 
                '-August' => 'August', 
                '-September' => 'September', 
                '-October' => 'October', 
                '-November' => 'November', 
                '-December' => 'December', 
                );

                foreach($vars as $val => $name){
                    if($_SESSION['sv_07'] == $val){
                        echo '<option value="' . substr($val, 0, 1) . '" selected>' . $name . '</option>';
                    } else {
                        echo '<option value="' . substr($val, 0, 1) . '">' . $name . '</option>';
                    }
                }

                echo '</select><select  name="sv_08">';

                $vars = array(
                '-Year' => 'Year',
                '-2012' => '2012', 
                '-2011' => '2011', 
                '-2010' => '2010', 
                '-2009' => '2009', 
                '-2008' => '2008', 
                '-2007' => '2007', 
                '-2006' => '2006', 
                '-2005' => '2005', 
                'Pre 2005' => 'Pre 2005', 
                );

                foreach($vars as $val => $name){
                    if($_SESSION['sv_08'] == $val){
                        echo '<option value="' . substr($val, 0, 1) . '" selected>' . $name . '</option>';
                    } else {
                        echo '<option value="' . substr($val, 0, 1) . '">' . $name . '</option>';
                    }
                }

                echo '</select></div>'; 

echo<<<EOD          


<div class="continue"><input type="submit" value="Continue" /></div>
</div>

</div>
</form>
EOD;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T18:27:47+00:00Added an answer on June 7, 2026 at 6:27 pm

    As opposed to standard HTML+PHP? This works fine with templating tools too.

    public function render() {
    ?>
    <html>
        <head>
            <title><?= $this->title ?></title>
        </head>
        <body>
            <h1>This is my awesome page</h1>
    
            <p>Choose from a menu.</p>
            <?php $this->renderMenu() ?>
    
            <p>Or enter your details:</p>
            <?php $this->renderForm() ?>
        </body>
    </html>
    <?php
    }
    

    If this isn’t what you’re getting at, show some code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Context I'm working on a project that I'd like to make more dynamic with
I created dynamic web project , and add 2 items : index.jsp page like
I have a Create View page in my MVC3 project to create instances of
I have create a LINQ-to-SQL project in Visual Studio 2010 using Dynamic Data. In
As I was attempting to create a Dynamic Web Project in eclipse I received
I am required to create a project similar to that of the ff. pic.
If I create a utility project and multiple dynamic web projects within Eclipse and
before reading my problem this work in a normal dynamic web project i create
I've recently been using Angularjs in my project. I'm trying to create a dynamic
In Eclipse, the folder structure when I create a Dynamic Web Project is [srikanth@hana

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.