0

Kindly pardon me if i looks silly as i am new in PHP and learning stuffs from SO .

I will try to explain clearly as possible what i am into

Currently i have a profile page for different level of users like

Admin, Level1, Level2, Level3

Fields are not same for all the 4 profile pages .

For level 1 i will display Name,Age,Picture

and

For Level 2 i will display Name,Picture,Location,Country

and

some other for Level3

The above i have done and it's working without any issues .

Now what i need was to make the admin to select the form fields dynamically . Like , there should be a setting kind of page in admin where i will list all the needed fields for different level of users under the level name with a check box near it(which i done).

Now the confusion was the admin can check what fields needed and that will reflect in that profile page of that user , Which i am confused on how to proceed as i cant get any idea on how to proceed . Also he should be able to add extra field (text box only allowed) like he will click add and enter the label name . this newly added text box should be functional like storing the value in db and retrieving.

Hope i explained clearly . if you are not clear with any stuffs kindly pardon me and make a comment i will explain further on that .

I needed help on getting a idea or structure on how to proceed for my requirement.

5
  • 1
    You can create a table in your database, a column for the input type, a column for the name tag, and a column for the privilege of who will use this field. Commented May 11, 2016 at 7:07
  • @LoganWayne Thanks mate for the idea. i will work on that and will let you know how it comes up. Can you kindly help with an idea of adding the field by himself as i mentioned in last paragraph Commented May 11, 2016 at 7:25
  • Are you referring to the admin or to the user when you said that adding the field by himself? Commented May 11, 2016 at 8:31
  • @LoganWayne admin mate Commented May 11, 2016 at 8:35
  • 1
    You can just add a new field to the input_tb. Commented May 11, 2016 at 8:39

1 Answer 1

1

You can create a table in your database, a column for the input type, a column for the name tag, and a column for the privilege of who will use this field.

Table (input_tb) will look like this:

input_id | input_type | name_tag |   label  |  user_type
---------+------------+----------+----------+-------------
    1    |    text    |   name   |   Name   |     1 /* ASSUMING 1 IS FOR LEVEL 1 PROFILE */
    2    |   number   |   age    |    Age   |     1
    3    |    file    |  picture |  Picture |     1

Assuming your user_tb looks like this:

user_id | user_type
--------+-----------
   1    |     1 /* MEANS THAT USER 1 HAS A LEVEL 1 PROFILE */

So, when a user accessed the form, you fetch the corresponding rows in the input_tb (assuming you store the user_type on a session below):

$stmt = $con->prepare("SELECT input_id, input_type, name_tag, label FROM input_tb WHERE user_type = ?");
$stmt->bind_param("i", $_SESSION["user_type"]);
$stmt->execute();
$stmt->bind_result($inputid, $inputtype, $nametag, $label);
while($stmt->fetch()){
    echo $label.': <input type="'$inputtype..'" name="'.$nametag.'"><br>';
}
$stmt->close();

Then, the information will be stored in another table:

Example of info_tb, using a single sample user here:

info_id | user_id | input_id |   input_data 
--------+---------+----------+-----------------
   1    |    1    |    1     |    Richard      /* User 1's Name */
   2    |    1    |    2     |       18        /* User 1's Age */
   3    |    1    |    3     | profile_pic.png /* User 1's Picture */

Reminder:

  • You can also consider having a condition to your code, when an input field is a textarea
  • Put a condition, when an input field is a file type. It has to go the process of uploading before inserting the corresponding file name to the database
Sign up to request clarification or add additional context in comments.

1 Comment

Really thanks a lot mate. as per your answer i will proceed and will update the status here mate

Your Answer

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.