Home Ask Login Register

Developers Planet

Your answer is one click away!

Storm Spirit February 2016

I have custom form loop and the radio value are override

I have this on my DB: enter image description here

then this is on my backend

    foreach($form['questions'] as $question) :

        $options = $question['options'];
        $options = explode(',',$options);

        <div class="form-group">
            <input type="hidden" value="<?php echo $question['label']; ?>" name="custom_form[label][]" />
            <label><?php echo $question['label']; ?></label>
            <?php if($question['type'] == 'text'): ?>
                <input type="text" placeholder="<?php echo $question['label']; ?>" name="custom_form[answer][]" class="form-control" required />
            <?php elseif($question['type'] == 'textarea'): ?>
                <textarea name="custom_form[answer][]" placeholder="<?php echo $question['label']; ?>" class="form-control" required></textarea>
            <?php elseif($question['type'] == 'radio'): ?>

                <div class="input-group btn-group" data-toggle="buttons">
                    <?php foreach($options as $option): ?>
                        <label class="btn btn-default"><input type="radio" name="custom_form[answer][]" value="<?php echo $option; ?>" required><?php echo $option; ?></label>
                    <?php endforeach; ?>
            <?php elseif($question['type'] == 'select'): ?>
                <select class="form-control" name="custom_form[answer][]" required>
                    <option value=""></option>
                    <?php foreach($options as $option): ?>
                        <option><?php echo $option; ?></option>
                    <?php endforeach; ?>


Aragoth February 2016

<input type="radio" name="custom_form[answer][]" />

As far as I can see, you are using the same name for your inputs.

Since it is an array it doesnt bother with the text inputs.

But radio buttons work differently, you have 2 groups of radio buttons with the same name, so although the css shows them as two sepparate entities, when you submit the form it will be parsed as only one radio button group.

My solution would be to change the name of the radio inputs to something like


Post Status

Asked in February 2016
Viewed 3,440 times
Voted 8
Answered 1 times


Leave an answer

Quote of the day: live life