0

I have this code to populate rows of a table in a php form

$html = '<tr>'; 
            $html .= '<td class="tg-yw4l"><input type="text" name="exam_date_input[]" value="' . $exam_date . '"></td>';
            $html .= '<td class="tg-yw4l"><input type="text" name="exam_code_input[]" value="' . $exam_code . '"></td>';
            $html .= '<td class="tg-yw4l"><input type="text" name="exam_title[]" value="' . $title . '"></td>';
            $html .= '<td class="tg-yw4l"><input type="text" name="exam_time_input[]" value="' . $exam_time . '"></td>';
            $html .= "<td class='tg-yw4l'><a href='javascript:void(0)' class='row_remove'> - </a></td>";
$html .= '<tr>';
die($html);

This is HTML is shown when I inspect the element

<input name="exam_date_input[]" value="01/03/2017" type="text">

Submitting the form should, in theory, add this array to the $POST array.

This isn't happening however.

Instead this code on my form action page $date = $_POST['exam_date_input']; gives the following notice:

Notice: Undefined index: exam_date_input

And there isn't an array of exam_date_input in the $POST array using var_dump($_POST);

2
  • How is this form being submitted? That die() command implies that this is the entirety of your HTML, which means there is no actual form. What are you even submitting? Commented Mar 7, 2017 at 14:38
  • What does print_r($_POST); show you? There won't be a $_POST['exam_date_input'] given those inputs. Commented Mar 7, 2017 at 15:40

1 Answer 1

1

The input is not inside the form, hence when you post the form, your input is not added to the parameters. The die seems to be incorrect, since you need to close the opened tags, including the body and the html. The solution is to make sure that you do not close the form before the input, but after your whole table and to use echo instead of die.

Sign up to request clarification or add additional context in comments.

3 Comments

I had added some div tags within the form for styling purposes. This had caused the input fields within the table to appear outside the form. Changing the HTML markup has fixed this.
@IanButler if my answer solved your problem, then don't forget to mark it as the correct answer. If not, then please edit your question with the HTML you currently have and led me know about it.
I've put it as correct as it made me look at my code in the correct way. I probably didn't phrase the question very well though. It is tricky when there is so much different code going on to post the relevant pieces...

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.