Reputation: 201
I have added a button onclick function to a web form, so that onClick new input text field is created. However when the forms posts to email, Quote_Num value isn't posted - it just says "Array"
JS
var counter = 1;
var limit = 8;
function addInput(divName) {
if (counter == limit) {
alert("You have reached the limit of adding " + counter + " inputs");
}
else {
var newdiv = document.createElement('div');
newdiv.innerHTML = "Quote Number " + (counter + 1) + " <p><input type='text' name='Quote_Num[]' /></p>";
document.getElementById(divName).appendChild(newdiv);
counter++;
}
}
HTML
<div id="dynamicInput">
Quote Number
<p><input type="text" id="Quote_Num" name="Quote_Num[]" class="required" /> *</p>
</div>
<p><button type="button" value="Add another text input" onClick="addInput('dynamicInput');">Add Quote Number</button></p>
PHP
<?php
$Quote_Num = $_POST["Quote_Num"];
foreach ($Quote_Num as $eachInput)
{
echo $eachInput . "<br>";
}
?>
Anyone with my experience with PHP help me get the form to post value of Quote_Num?
Upvotes: 0
Views: 65
Reputation: 1509
The variable $Quote_Num
set with $Quote_Num = $_POST["Quote_Num"];
is an array, as you are submitting more then one values values from your HTML form by setting name equal to Quote_Num[]
.
If you echo
an Array
in PHP, It will give an Notice, and print 'Array'.
If you want all of the values of the array $Quote_Num
you can use implode
on Array. For example implode(", ", $Quote_Num)
will return comma separated list of all values in the array as String.
You may also print the whole array by using var_dump
or print_r
.
I hope, I got your question and it helps.
Upvotes: 1