0

I'm working on a form that allows a user to create their own surveys. Each survey has n number of questions, and n number of answers per question.

For example (Not tested this form, just an example):

<form action="/add-survey" method="POST">
    <label for="question_1">Question 1</label>
    <input type="text" name="question[]">

    <ul id="answers">
        <li class="answer">
            <label for="answer_1">Answer 1</label>
            <input type="text" name="...."> /* What do I do here? */
        </li>
    </ul>
</form>

When I submit the form, in the PHP script I would like to access the forms like so:

$_POST['question'][0]['answer'][0] // Question 1, answer 1

If I set the name attribute to answer[] I end up with two arrays question and answer, which makes it difficult to work with.

Is this possible at all?

1 Answer 1

2

try this on your answer input

<input type="text" name="question[][answer][]">
Sign up to request clarification or add additional context in comments.

Comments

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.