Form Drop down

I am working on a contact form but I am having difficulty putting in a drop down menu to input text. Can someone give me a hand.

http://coloradorestaurantlist.com/?a...aurants_Submit

Thanks
Jamie

Maybe use php echo for debug. Hope below that help.

http://www.html-form-guide.com/php-form/php-form-select.html

Ked :slight_smile:

Sorry… Here is the link:

http://coloradorestaurantlist.com/?a=Colorado-Restaurants_Submit

I want to make a city section that has a drop down menu of a list of cities.

Thanks
Jamie

I have gotten the drop down box, but it is still not working right. It is now seeing the selection as text. Can some one help me?

Here is the form:http://coloradorestaurantlist.com/?a=Colorado-Restaurants_Submit

Here is my code:

  <?php

if(isset($_POST['city'])) { $city = $_POST['city']; } else { $city = ''; }
if(isset($_POST['name'])) { $name= $_POST['name']; } else { $name = ''; }
if(isset($_POST['phone'])) { $phone= $_POST['phone']; } else { $phone = ''; }
if(isset($_POST['address'])) { $message= $_POST['address']; } else { $address = ''; }

$form = "
<form method='post'>
<p>
*City:
</p>
<p>
<select>
<option type='text' name='city' value='$city'>Fresh Milk</option>
<option type='text' name='city' value='$city'>Old Cheese</option>
<option type='text' name='city' value='$city'>Hot Bread</option>
</select>
</p>


<p>
Restaurant Name:
</p>
<p>
<input type='text' name='name' value='$name' >
<p>
<p>
*Phone:
</p>
<p>
<input type='text' name='phone' value='$phone' >
</p>
<p>
*Restaurant Address:
</p>
<p>
<input type='text' name='address' value='$address' >
</p>
<p>
<input type='submit' name='submit' value='Submit' class='submit' >
</p>
<p>
*required fields
</p>
</form>";

if(isset($_POST['submit'])) {

    $errors = array();
    if(strlen( $_POST['city'] ) == 0) { $errors[] = "Please select a city"; }
    if(strlen( $_POST['name'] ) == 0) { $errors[] = "Please provide the restaurant name"; }
	if(strlen( $_POST['phone'] ) == 0) { $errors[] = "Please provide the restaurant phone"; }
    if(strlen( $_POST['address'] ) == 0) { $errors[] = "Please provide the restaurant address"; } 

    if(count($errors) == 0) {
        $header = 'From: ' .$_POST['email'] .'\\r\
Content-type: text/plain; charset=iso-8859-1\\r\
';
        $body = '\\City:: '. $_POST['city'];
        $body .= '\\Name:: '. $_POST['name'];
        $body .= '\\Phone:: '. $_POST['phone'];
        $body .= '\\Address:: '. $_POST['address'];
        $body = wordwrap($body,70);
        $send = mail('info@coloradorestaurantlist.com', 'Form submitted from your website',$body, $header);
        if($send){ echo '<h3>Your request to add a restaurant has been submitted...</h3>'; }
        else{ echo '<h3>There was a problem with your submission....</h3>'; }
        }
    else { foreach($errors as $error) { echo ("$error <br>"); } echo $form; }

    }
else { echo $form; }

?></p>

Hi,
Maybe try this one, and you need to tune some code for your case:

Ked

Remove both instances of strlen from here:

if(strlen( $_POST['city'] ) == 'Select a City') { $errors[] = "Please select a city"; }
	if(strlen( $_POST['food'] ) == 'Select a Food Type') { $errors[] = "Please select a food type"; }

Strlen returns the length of the string, so strlen( $_POST[‘city’] ) would return 13 not ‘select a city’ like you’re expecting.

I have gotten everything figured out. I just want to post an error if someone doesn’t select a city or a food type. Any suggestion why it is not working?

  <?php

if(isset($_POST['city'])) { $city = $_POST['city']; } else { $city = ''; }
if(isset($_POST['food'])) { $food = $_POST['food']; } else { $food = ''; }
if(isset($_POST['name'])) { $name= $_POST['name']; } else { $name = ''; }
if(isset($_POST['phone'])) { $phone= $_POST['phone']; } else { $phone = ''; }
if(isset($_POST['address'])) { $address= $_POST['address']; } else { $address = ''; }

$form = "
<form method='post'>
<p>
*City:
</p>
<p>
<select type='text' name='city' value='$city'>
<option selected>Select a City</option>
<option>Air Force Academy</options>
<option>Alomosa</options>
<option>Applewood</options>
<option>Arvada</options>
<option>Aurora</options>
<option>Berkley</options>
<option>Black Forest</options>
<option>Boulder</options>
<option>Brighton</options>
<option>Broomfield</options>
<option>Canon City</options>
<option>Castle Rock</options>
<option>Castlewood</options>
<option>Cimarron Hills</options>
<option>Clifton</options>
<option>Colorado Springs</options>
<option>Columbine</options>
<option>Commerce City</options>
<option>Cortez</options>
<option>Craig</options>
<option>Delta</options>
<option>Denver</options>
<option>Derby</options>
<option>Durango</options>
<option>Edwards</options>
<option>Englewood</options>
<option>Erie</options>
<option>Evans</options>
<option>Evergreen</options>
<option>Federal Heights</options>
<option>Fort Carson</options>
<option>Fort Collins</options>
<option>Fort Lupton</options>
<option>Fort Morgan</options>
<option>Fountain</options>
<option>Fruita</options>
<option>Fruitvale</options>
<option>Glenwood</options>
<option>Golden</options>
<option>Grand Junction</options>
<option>Greeley</options>
<option>Greenwood</options>
<option>Gunbarrel</options>
<option>Highlands Ranch</options>
<option>Ken Caryl</options>
<option>La Junta</options>
<option>Lafayette</options>
<option>Lakewood</options>
<option>Lamar</options>
<option>Littleton</options>
<option>Longmont</options>
<option>Louisville</options>
<option>Loveland</options>
<option>Montrose</options>
<option>Northglenn</options>
<option>Orchard Mesa</options>
<option>Parker</options>
<option>Pueblo West</options>
<option>Pueblo</options>
<option>Redlands</options>
<option>Rifle</options>
<option>Security-Widefield</options>
<option>Sherrelwood</options>
<option>Southglenn</options>
<option>Steamboat Springs</options>
<option>Sterling</options>
<option>Stonegate</options>
<option>Stratmoor</options>
<option>Superior</options>
<option>The Pinery</options>
<option>Thornton</options>
<option>Trinidad</options>
<option>Twin Lakes</options>
<option>Welby</options>
<option>Westminster</options>
<option>Wheat Ridge</options>
<option>Windsor</options>
<option>Woodland Park</options>
<option>Woodmoor</options>
</select>
</p>

<p>
*Food Type:
</p>
<p>
<select type='text' name='food' value='$food'>
<option selected>Select a Food Type</option>
<option>American</option>
<option>Asian</option>
<option>Barbecue</option>
<option>French</option>
<option>German</option>
<option>Greek</option>
<option>Indian</option>
<option>Italian</option>
<option>Mexican</option>
<option>Seafood</option>
<option>Everything else</option>
</select>
</p>

<p>
*Restaurant Name:
</p>
<p>
<input type='text' name='name' value='$name' >
<p>
<p>
*Phone:
</p>
<p>
<input type='text' name='phone' value='$phone' >
</p>
<p>
*Restaurant Address:
</p>
<p>
<input type='text' name='address' value='$address' >
</p>
<p>
<input type='submit' name='submit' value='Submit' class='submit' >
</p>
<p>
*required fields
</p>
</form>";

if(isset($_POST['submit'])) {

    $errors = array();
    if(strlen( $_POST['city'] ) == 'Select a City') { $errors[] = "Please select a city"; }
	if(strlen( $_POST['food'] ) == 'Select a Food Type') { $errors[] = "Please select a food type"; }
    if(strlen( $_POST['name'] ) == 0) { $errors[] = "Please provide the restaurant name"; }
	if(strlen( $_POST['phone'] ) == 0) { $errors[] = "Please provide the restaurant phone"; }
    if(strlen( $_POST['address'] ) == 0) { $errors[] = "Please provide the restaurant address"; } 

    if(count($errors) == 0) {
        $header = 'From: ' .$_POST['email'] .'\\r\
Content-type: text/plain; charset=iso-8859-1\\r\
';
        $body = '\\City:: '. $_POST['city'];
		$body = '\\Food-Type:: '. $_POST['food'];
        $body .= '\\Name:: '. $_POST['name'];
        $body .= '\\Phone:: '. $_POST['phone'];
        $body .= '\\Address:: '. $_POST['address'];
        $body = wordwrap($body,70);
        $send = mail('info@coloradorestaurantlist.com', 'Restaurant Submission Request',$body, $header);
        if($send){ echo '<h3>Your request to add a restaurant has been submitted...</h3>'; }
        else{ echo '<h3>There was a problem with your submission....</h3>'; }
        }
    else { foreach($errors as $error) { echo ("$error <br>"); } echo $form; }

    }
else { echo $form; }

?></p>