PHP Form Help

Discussion in 'PHP' started by cport1, Nov 25, 2009.

  1. #1
    I can't seem to figure out what is not allowing this work...

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <link href="form.css" rel="stylesheet" type="text/css" />
    
    <script src="http://code.jquery.com/jquery-latest.js"></script>
      <script type="text/javascript" src="http://dev.jquery.com/view/trunk/plugins/validate/jquery.validate.js"></script>
    <style type="text/css">
    * { font-family: Arial, Helvetica, sans-serif;}
    label { width: 20; float: left; }
    .required
    {
    background:#aee5c4;
    width:225px;
    }
    label.error { float: none; color: red; padding-left: .5em; vertical-align: top; }
    p { clear: both; }
    .submit { margin-left: 6em; }
    em { font-weight: bold; padding-right: 1em; vertical-align: top; }
    </style>
      <script>
      $(document).ready(function(){
        $("#form").validate();
      });
      </script> 
    
    </head>
    
    <body>
    <div id="top">
      <div align="center"><img src="images/top.png"/></div>
    </div>
    <div id="bottom">
    <br />
    <p></p>
    <form action="mailer.php" method="post" id="form">
      <div class="box">
        <div class="box">
          <h1>Free Consultation!</h1>
          <label> <span>First Name*  </span>
          <input type="text" id="fname" name="fname"  class="required" minlength="2"/>
          </label>
          <label> <span>Last Name*  </span>
          <input type="text" id="lname" name="lname"  class="required" minlength="2"/>
          </label>
          <label> <span>Email*  </span>
          <input name="email" id="email" type="text"  class="required email" />
          </label>
          <label> <span>Company*  </span>
          <input name="company" for="company" type="text" id="company"  class="required" minlength="2"/>
          </label>
          <label> <span>Phone*  </span>
          <input name="phone" id="phone" type="text" class="input_text" minlength="10"/>
          </label>
          <label> <span>Address  </span>
          <textarea name="address" id="address" cols="50" rows="4" class="input_text">
        </textarea>
          </label><br /><br /><br /><br /><br />
        
         Interested Services:<br />
          <input type="checkbox" name="check[]"  value="Web_Design" /> Web Design and Development<br />
          <input type="checkbox" name="check[]"  value="Video_Production" />Video Production<br />
          <input type="checkbox" name="check[]"  value="SEO" />Search Engine Optimization<br />
          <input type="checkbox" name="check[]"  value="AdWords" />Google AdWords<br />
          <input type="checkbox" name="check[]" value="Social_Marketing" />Social Marketing<br /> 
          
            
            <center><input type="image" class="button" value="Submit Form" src="images/submit.png" onchange="validate (this.value)"/></center>
          
        </div>
        
    </div><!--div box-->
    </form></p>
    
    
    </div><!--div bottom-->
    </body>
    </html>
    
    PHP:
    <?php
    if(isset($_POST['submit'])) {
    
    	$to = "test@libertybelltelecom.com"; 
    	$subject = "GrowthServicesConsultation";
    	//$fname = $_POST['fname'];
    	//$lname = $_POST['lname'];
    	//$email = $_POST['email'];
    	//$company = $_POST['company'];
    	//$phone = $_POST['phone'];
    	//$address = $_POST['address'];
    
    	foreach($_POST['check'] as $value) {
    		$check_msg .= "Checked: $value\n";
    	}
    	
    	$body = "First Name: $fname\n Last Name: $lname\n E-Mail: $email\n $check_msg Company: $company\n Phone: $phone\n Address: $address\n";
    
    	echo "Data has been submitted to $to!";
    	mail($to, $subject, $body);
    	
    } else {
    	echo "blarg!";
    }
    ?>
    PHP:

     
    cport1, Nov 25, 2009 IP
  2. papsyface

    papsyface Peon

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    The PHP script checks to see if $_POST['submit'] is set - but it never is. The reason is because you forgot to name your submit image.

    So replace this:
    <center><input type="image" class="button" value="Submit Form" src="images/submit.png" onchange="validate (this.value)"/></center>

    With this:
    <center><input name="submit" type="image" class="button" value="Submit Form" src="images/submit.png" onchange="validate (this.value)"/></center>
     
    papsyface, Nov 25, 2009 IP
  3. javaongsan

    javaongsan Well-Known Member

    Messages:
    1,054
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    128
    #3
    Try return true in your javascript
     
    javaongsan, Nov 25, 2009 IP
  4. adolix

    adolix Peon

    Messages:
    787
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Mate, try using a web form generator service. No more programming hassle, all you do is design your form and copy & paste the final HTML code on your website.
     
    adolix, Nov 25, 2009 IP
  5. LittleJonSupportSite

    LittleJonSupportSite Peon

    Messages:
    386
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I don't think you will have an onChange event for a submit button or image.

    Maybe you are looking for onClick?
     
    LittleJonSupportSite, Nov 26, 2009 IP
  6. prasanthmj

    prasanthmj Member

    Messages:
    62
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    45
    #6
    Use the forms' onsubmit() for JS validation. A Form Validation script might help.

    Also this check: if(isset($_POST['submit'])) won't work.
    You could probably add a hidden input field to indicate submission
    <input name='submit' value='1'>
     
    prasanthmj, Nov 26, 2009 IP