1

I am trying to create a form builder that will enable users generate survey form/page.

After the form is generated the form attribute is stored on a table.

Question 1: Where can I store the form attribute knowing fully well that the number of fields user might add in the form is unknown.

Question 2: Where and how do I store data submitted through the generated form when some one for example completes the survey form.

Should I create new tables on fly for each of the form attributes? If yes what if over a million forma are created which translates to a million tables.

Is this where multi-tenancy comes into play.

Please provide your answer based on best practices.

asked Feb 6, 2016 at 20:27

1 Answer 1

1

I think I get what you're asking, but why not create one table with 100 columns, labelled 1-100. Set a limit on the amount of fields a user can create(Limit 100). Then, POST the fields and add a sql query to store the values...?

COMMENT ANSWER If the user is already signed in filling this form I would personally do the POST request on the same page.

<?php if (isset($_POST['field1'])){
 $valueforField1 = $_POST['field1'];
 $valueforField2 = $_POST['field2'];
 $valueforField3 = $_POST['field3'];
 $servername = "localhost";
 $username = "username";
 $password = "password";
 $dbname = "myDB";
 // Create connection
 $conn = new mysqli($servername, $username, $password, $dbname);
 // Check connection
 if ($conn->connect_error) {
 die("Connection failed: " . $conn->connect_error);
 } 
 $sql = "INSERT INTO Survey (field1, field2, field3) // I guess you would `have to add 100 fields here to accommodate the fields in your DB Also, you can set a default value in MySQL that way if field 56-100 is not set it has a value like 0 or add the value in this php file` 
 VALUES ('$valueforField1', '$valueforField2', '$valueforField3')";
 if ($conn->query($sql) === TRUE) {
 echo "New record created successfully";
 } else {
 echo "Error: " . $sql . "<br>" . $conn->error;
 }
 $conn->close(); ?>

COMMENT ANSWER or if you want to wait for the user to log in you can store all the values in a SESSION variable.

<?php
session_start();
if (isset($_POST['field1'];)){
if (!(isset($_SESSION['email']))){
$_SESSION['field1'] = $_POST['field1'];
// You would have to do 100 of these
}
}
?>
answered Feb 6, 2016 at 20:40
Sign up to request clarification or add additional context in comments.

1 Comment

sounds like a nice idea. Like you said here add a sql to store the the POST or data/values where do I store the post values?

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.