Douglas Littlefield
Douglas Littlefield

Reputation: 27

Dropdown box is not sending in form data via php

This is prob something simple I am missing. I have an html page with a form on it:

<form action="http://URL/mailer.php" id="contact_form" method="post">

Inside that form are your basic text boxes with the exception of 1 drop down box.

<select id="boardtype">
        <option selected value="base">Please Select</option>
        <option value="Raspberry">Raspberry PI Series</option>
        <option value="OrangePi">OrangePi series</option>
        <option value="BananaPi">Banana Pi series</option>
        <option value="Odroid">Odroid series</option>
        <option value="Asus">Asus series</option>
        <option value="Udoo">Udoo series</option>
    </select>
    <br />
    <select id="boardstyle">
        <option>Please choose from above</option>
    </select>

This looks at : (Removed the code that did not have anything to do with this)

<script>
    $(function() {

        $("#boardtype").change(function() {
            $("#boardstyle").load("textdata/" + $(this).val() + ".txt");
        });

And then inside a folder called "textdata" it looks at 7 text documents that populate the values below. and that makes something like this form:

screenshot1

DropdownBox First Box:

screenshot2

and based on the value of Dropdown box1 it will populate Drop down box 2 - that looks something like This:

screenshot3

So that then is sent via a phpscript called mailer.php

$first = $_POST["first"];
$last = $_POST["last"];
$email = $_POST["email"];
$serial = $_POST["serial"];
$boardtype = $_POST["boardtype"];
$boardstyle = $_POST["boardstyle"];
$referred = $_POST["referred"];
$text = "{ $first $last
$referred
$email
$boardtype
$boardstyle
$serial
}
";
$file = fopen("rc3.key","a+");
fwrite($file, $text);
fclose($file);

So i thought if i added the $boardtype & $boardstyleit would pull the information from the dropdown box, however its not entering any data for those two fields

{ Bill Gates
John Scott
[email protected]


039393920
}

There should be 2 items under the email...

Im sorry for how long this is, i was just trying to put as much information as i could. And just so its on here, the other form data that works is formatted just like this:

<input type="text" name="referred" id="referred" value="" class="requiredField" onblur="if(this.value == '') { this.value = 'Referred By'; }" onfocus="if(this.value == 'Referred By') { this.value = ''; }" style="color: #FFFFFF; border: 1px solid #000000; padding-left: 4px; padding-right: 4px; padding-top: 1px; padding-bottom: 1px; background-color: #3399CC" size="37" /></td>

<input type="text" name="first" id="first" value="" class="requiredField" onblur="if(this.value == '') { this.value = 'First Name'; }" onfocus="if(this.value == 'First Name') { this.value = ''; }" style="color: #FFFFFF; border: 1px solid #000000; padding-left: 4px; padding-right: 4px; padding-top: 1px; padding-bottom: 1px; background-color: #3399CC" size="37" /></td>

The rest of the form is formatted just like that, Figure no need to post the other text boxes...

Upvotes: 1

Views: 917

Answers (1)

Ayo K
Ayo K

Reputation: 1774

What php actually reads are elements with the specified name.

So $boardstyle = $_POST["boardtype"]; means php will look for an element with name 'boardtype'.

So add the name property to your select

<select id="boardtype" name="boardtype">
.
.
.

Upvotes: 2

Related Questions