-3

I am new to PHP and trying to get a simple form working and be able to be emailed to an administrator. I've gotten PHP forms to work before, but for some reason am having a lot of difficulty with this. Basically, when I hit my submit button, I get this garbage: enter image description here. I am using a WAMP server to accomplish this, not sure if iit has anything to do with the error but I don't believe it does.

This is my script on the main index page, just before closing html

    function validate(){
        var name=document.getElementById('employee');
        var name=document.getElementById('start-date');
        var name=document.getElementById('end-date');
        var name=document.getElementById('location');
        var name=document.getElementById('company');
        var name=document.getElementById('perdiem');
        var name=document.getElementById('flight');
        var name=document.getElementById('hotel');
        var name=document.getElementById('rental');
        var name=document.getElementById('depart');
        var name=document.getElementById('city-venue');
        var name=document.getElementById('submit');

        if(employee.value == ''){
            alert('Please enter employee name');
            return false;
            }
        if(start-date.value == ''){
            alert('Please enter start date');
            return false;
            }
        if(end-date.value == ''){
            alert('Please enter end date');
            return false;
            }   
        if(location.value == ''){
            alert('Please enter location');
            return false;
            }   
        if(company.value == ''){
            alert('Please enter employee company');
            return false;
            }   
        if(perdiem.value == ''){
            alert('Please enter perdiem value');
            return false;
            }
        if(depart.value == ''){
            alert('Please enter departure details');
            return false;
            }   
        if(city-venue.value == ''){
            alert('Please enter City-Venue');
            return false;
            }   
        }

Here is the form:

<div id="form">
<form method="get" name="contactform" action="handler.php" onSubmit="return validate()"> 
<h1>Employee to Request</h1>

<select id="employee">
<option value="emp1">sample1</option>
<option value="emp2">sample2</option>

</select><br>

<h1>Start Date:</h1> <input type="date" name="start-date"><br>
<h1>End Date:</h1> <input type="date" name="end-date"><br>
<h1>Location</h1>
<select id="location">
  <option value="chicago">Chicago</option>
  <option value="florida">Florida</option>
  <option value="las-vegas">Las Vegas</option>
  <option value="new-england">New England</option>
  <option value="new-orleans">New Orleans</option>
  <option value="new-york">New York</option>
  <option value="northern-california">Northern California</option>
  <option value="seattle">Seattle</option>
  <option value="southern-california">Southern California</option>
  <option value="washington-dc">Washington DC / Baltimore</option>  
</select>
<h1>Company Name</h1>
<select id="company">
  <option value="cmp1">cmp1</option>
  <option value="cmp2">cmp2</option>
  <option value="cmp3">cmp3</option>
</select>
<h1>Perdiem</h1>
<select id="perdiem">
  <option value="35">$35</option>
  <option value="45">$45</option>
  <option value="50">$50</option>
</select>
<h1>Hotel</h1>
<select id="hotel">
  <option value="yes">Yes</option>
  <option value="no">No</option>
</select>
<h1>Flight</h1>
<select id="flight">
  <option value="yes">Yes</option>
  <option value="no">No</option>
</select>
<h1>Rental Car</h1>
<select id="rental">
  <option value="yes">Yes</option>
  <option value="no">No</option>
</select>

<h1>Departing</h1>
<input type="text" name="depart" onClick="this.value='';" onFocus="this.select()" onBlur="this.value=!this.value?'Name: ':this.value;" value="Departing: " placeholder="Depart"><br>
<h1>City / Venue</h1>
<select id="city-venue">
  <option value="city1">Las Vegas / Venue1</option>
  <option value="city2">Orlando / Venue2</option>
  <option value="city3">sample</option>
  <option value="city4">sample2</option>
  <option value="city5">sample3</option>
</select>
<br>

<h1>Other Information:</h1>
<textarea class="message" placeholder="Other Information:"type="text" name="message" onClick="this.value='';" onFocus="this.select()" onBlur="this.value=!this.value?'Message: ':this.value;" value="Message: "></textarea><br>
<input type="submit" value="Submit" id="submit">
</form>
</div> <!--close form-->

and here is handler.php file

<?php 
$employee = $_GET['employee'];
$employee = $_GET['start-date'];
$employee = $_GET['end-date'];
$employee = $_GET['location'];
$employee = $_GET['company'];
$employee = $_GET['perdiem'];
$employee = $_GET['flight'];
$employee = $_GET['hotel'];
$employee = $_GET['rental'];
$employee = $_GET['depart'];
$employee = $_GET['city-venue'];

echo "Welcome".$employee;
echo "</br>"
?>

Thanks in advance, I really appreciate it

aksu
  • 5,221
  • 5
  • 24
  • 39
Barret LaPlante
  • 141
  • 1
  • 1
  • 7
  • possible duplicate of [Reference - What does this error mean in PHP?](http://stackoverflow.com/questions/12769982/reference-what-does-this-error-mean-in-php) – deceze Feb 19 '14 at 19:01
  • 1
    None of your `form` fields have `name` attributes. `id` is not the same as `name` –  Feb 19 '14 at 19:02

3 Answers3

2

This is happening because php reads values from input name and not input id, so index is not definied, i would add name in your input, for example

<select id="employee">

Will be

<select id="employee" name="employee">

You have to add this all your input fields

Fabio
  • 23,183
  • 12
  • 55
  • 64
0

use isset() function

try this

if(isset($_GET['employee']))
    { 
     $employee = $_GET['employee'];
   }

and yes put name attribute in all your inputs

Nishant Solanki
  • 2,119
  • 3
  • 19
  • 32
  • This will manage to solve the error but it won't help in having all input values – Fabio Feb 19 '14 at 19:06
  • yeah you are right. but I think this is a best answer for this question. its easy to understand – Nishant Solanki Feb 19 '14 at 19:08
  • You are not exaplaining anything at all, how could that be the best answer? Someone needs to read some guideline http://meta.stackexchange.com/questions/7656/how-do-i-write-a-good-answer-to-a-question – Fabio Feb 19 '14 at 19:14
0

This has nothing to do with the PHP errors, but the JavaScript is full of problems

COPY PASTE ERROR

    var name=document.getElementById('employee');
    var name=document.getElementById('start-date');
    var name=document.getElementById('end-date');
    var name=document.getElementById('location');
    var name=document.getElementById('company');
    var name=document.getElementById('perdiem');
    var name=document.getElementById('flight');
    var name=document.getElementById('hotel');
    var name=document.getElementById('rental');
    var name=document.getElementById('depart');
    var name=document.getElementById('city-venue');
    var name=document.getElementById('submit');

Not a valid Variable name

city-venue.value

That is saying take variable city and subtract venue.value

Now the PHP errors - Form issue

You are not submitting name/value pairs to the serber. The issue with your form is the elements just have ids and no names. All of your form elements need names. That is what is submitted to the server.

epascarello
  • 204,599
  • 20
  • 195
  • 236