I have a form to email php script. The context of the website makes it necessary for me to add repeating form fields at the User's click of a button. How do I properly handle the form input? For example I have a Vehicle form and when the User click's add vehicle I append a carbon copy of several of the vehicle's form groups. These form inputs have the same "name" and there for php is trying to access two or more form inputs of the same name in my script.
Should I store the inputs as an array somehow?
Here is my script:
<?php
$admin_email = "[email protected]";
$name = $_POST['name'];
$email = $_POST['email'];
$address = $_POST['address'];
$carrier = $_POST['carrier'];
$yes = $_POST['yes'];
$no = $_POST['no'];
$renewal = $_POST['renewal'];
$homephone = $_POST['homephone'];
$cellphone = $_POST['cellphone'];
$year = $_POST['year'];
$makemodel = $_POST['makemodel'];
$twowd = $_POST['twowd'];
$fourwd = $_POST['fourwd'];
$vin = $_POST['vin'];
$damage = $_POST['damage'];
$payment = $_POST['payment'];
$umuim = $_POST['umuim'];
$drivername = $_POST['drivername'];
$driverbday = $_POST['driverbday'];
$ssn = $_POST['ssn'];
$dlnumber = $_POST['dlnumber'];
$dlstate = $_POST['dlstate'];
$violations = $_POST['violations'];
$email_body = "Auto Quote\n From: $email \n $address, $carrier, $yes, $no, $carrier, $renewal, $homephone, $cellphone, $year, $makemodel, $twowd, $fourwd, $vin, $damage, $payment, $umuim, $drivername, $driverbday, $ssn, $dlnumber, $dlstate, $violations)";
mail($admin_email, "Auto Quote Request", $email_body);
echo "Thank you for contacting us!";
?>
So when I press the "add vehicle button" I append a copy of the form groups on my form from $year to $umuim. Is my current code capable of handling this? I have not had any errors when testing manually (I can't see what the email looks like as I don't have a mail server in development), but the echo statement at the end works.
One problem I could see is would the variable just reset after receiving the second input. Should I use an array somehow? Thanks.
$email_bodyas well if you want to see whats in the emailforeachloop on an element that has been POSTed as an array.