Jump to content
Sign in to follow this  

PHP Dynamic Form Setup ( For Survey Purpose )

Recommended Posts

Hi All,


i would like to create a web page that allow user to feedback. So, i need a page where allow admin to setup a survey form. The more flexible, the best. What i mean is, admin able to create a form. 

A form may contain of check box, Main question, Sub Question and also open text feed back.


For now, i able to complete only one module, which is allow admin add only Main Question, i have stuck with the Sub Questions.


Here is my sample codes.



HTML Page:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Test Market</title>
        <script src="http://jtable.org/Scripts/jquery-1.9.1.min.js" type="text/javascript"></script>
        <script src="http://jtable.org/Scripts/jquery-ui-1.10.0.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            var max_fields = 10; //maximum input boxes allowed
            var wrapper = $(".input_fields_wrap"); //Fields wrapper
            var add_button = $(".add_field_button"); //Add button ID

            var x = 1; //initlal text box count
            $(add_button).click(function (e) { //on add input button click
                if (x = x) { //max input box allowed
                    x++; //text box increment
                    $(wrapper).append('<div><input type="text" name="question[]"/><a href="#" class="remove_field">Remove</a></div>'); //add input box

            $(wrapper).on("click", ".remove_field", function (e) { //user click on remove text
            width: 297px;
            margin: 0 auto;
        <div id="b-wrapper">
            <form action="save-form.php?mod=add" method="post">
                        <td><lable>Form Name</lable></td>
                        <td><input name="form_name"></input></td>
                        <td><lable>Form Description</lable></td>
                        <td><input name="form_desc"></input></td>
                <div class="input_fields_wrap">
                    <div><input type="text" name="question[]"></input></div>
                <button class="add_field_button">Add More Fields</button>
                <input type="submit"></input>



$serverName = "server_one"; //serverName\instanceName
$connectionInfo = array("Database" => "RSA", "UID" => "username", "PWD" => "password");
$conn = sqlsrv_connect($serverName, $connectionInfo);

$formName = $_POST['form_name'];
$formDesc = $_POST['form_desc'];
$formQuestion = $_POST['question'];
$id = $_POST["id"];
foreach( $formQuestion as $key => $text_field ) {
  //print "$formQuetion";  echo '<br>';

//MySqli Insert Query
$result = "INSERT INTO form(form_name,form_description,question) VALUES('$formName','$formDesc','$text_field')";
$stmt = sqlsrv_query($conn, $result);


This only able to dynamically add main question, how if there is a sub question? radio button? selection? check box?



Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.