SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict
    Join Date
    Nov 2012
    Posts
    251
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Why doesn't my form work ?

    Well it works partially in that the form comes through, but the form is always blank. What have I done wrong.

    Extract from HTML

    HTML Code:
    <ul class="opendays">
     <li>
     <p><strong>Change of Peronal Details</strong></p>
     </li>
     </ul>
    
    
    
    
            <form action="send_contact.php" method="post">
            <ul class="opendays">
        
                      <li> <p>Your Name <required>*</required></p><p><input type="text"></p></li>
                        
                      <li><p>Your Email <required>*</required></p><p><input type="text"></p></li>
                        
                      <li><p>With Effect From <required>*</required></p><p><input type="text"></p></li>
                      
                      <li><p>Telephone No </p><p><input type="text"></p></li>
                                            
                      <li><p>Mobile Number </p><p><input type="text"></p></li>
                      
                      <li><p>Adress Line 1 </p><p><input type="text"></p></li>
                      
                      <li><p>Adress Line 2 </p><p><input type="text"></p></li>
                      
                      <li><p>Adress Line 3 </p><p><input type="text"></p></li>
                      
                      <li><p>Adress Line 4 </p><p><input type="text"></p></li>
                      
                      <li><p>Adress Line 5 </p><p><input type="text"></p></li>
                
                      <li><p>&nbsp</p><p><button type="submit" class="button">Submit</button></p></li>
                      </ul>
                      <br> <required> * (indicates that the information is required)
                                    </form>
    Extract from PHP

    PHP Code:
    <?php

    // Contact subject
     
    $subject ="$Contact Form"

    // Details
     
    $message="$detail"


    // Mail of sender
     
    $mail_from="$customer_mail"

    // From 
    $header="from: $detail <$mail_from>"


    // Enter your email address
     
    $to ='antonylambert@c5d.co.uk'

    $send_contact=mail($to,$subject,$message,$header);


     
    // Check, if message sent to your email 
    // display message "We've recived your information"
     
    if($send_contact){
     echo 
    "Thanks for sending this change of details. I shall update our records right away.";
     }
     else {
     echo 
    "ERROR";
     }
     
    ?>
    Please answer in words of one syllable please

    Antony
    Last edited by SpacePhoenix; Feb 8, 2013 at 16:35. Reason: placed php tags around php code

  2. #2
    SitePoint Mentor silver trophy
    Rubble's Avatar
    Join Date
    Dec 2005
    Location
    Cambridge, England
    Posts
    2,415
    Mentioned
    81 Post(s)
    Tagged
    3 Thread(s)
    148 posts and you are not putting your code in code and php tags

    How is the php code supposed to know what the telephone number is for example? There is no name set.
    HTML Code:
    <li><p>Telephone No </p><p><input type="text" name="telephone"></p></li>
    In the php page you need:
    PHP Code:
    $telephone $_POST['telephone']; 
    There are other things I would change/improve but try this first.

  3. #3
    SitePoint Addict
    Join Date
    Nov 2012
    Posts
    251
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, but where do I need it ?

    I'm sorry but this is all new to me and I can't crack it. 148 posts and 2 relating to PHP

    I've spent most of the day looking at web pages and a book, but just can't get it.

    All I want is a simple change of address form !

    Thanks

    Antony

  4. #4
    SitePoint Mentor silver trophy
    Rubble's Avatar
    Join Date
    Dec 2005
    Location
    Cambridge, England
    Posts
    2,415
    Mentioned
    81 Post(s)
    Tagged
    3 Thread(s)
    The name is the variable used in the php section so all your fields in your form need a name.

    For example:
    HTML Code:
    <li><p>Telephone No </p><p><input type="text"></p></li>
    Becomes
    HTML Code:
    HTML Code:
    <li><p>Telephone No </p><p><input type="text" name="telephone"></p></li>
    The variable needs to be set on the php page and depending on the php version there are different options but I think this is the current method:
    PHP Code:
    $telephone $_POST['telephone']; 
    The variable $telephone now contains the value from the telephone field in your form.

    Then in your email you need to add all these variables together and add to your email.

    It may be worth your while finding a form and modifying it to your needs; this is one I have used in the past:
    Contact form

  5. #5
    SitePoint Addict
    Join Date
    Nov 2012
    Posts
    251
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The thing I can't grasp is where do I put that $telephone = $_POST['telephone'];

    I appreciate that you must think me stupid but I know nothing of PHP.

    I want a simple contact form and was hoping to be able to do one myself. I think I shall have to stick with Jot-Form

    Antony

  6. #6
    SitePoint Mentor silver trophy
    Rubble's Avatar
    Join Date
    Dec 2005
    Location
    Cambridge, England
    Posts
    2,415
    Mentioned
    81 Post(s)
    Tagged
    3 Thread(s)
    A simple email form without any error reporting or user input validation - you should add those when you get your form working. I always start simple and build on it as you can find any errors/problems as you go.you have.

    This should show you where the different parts go. All on one page for the form and the php code.

    PHP Code:
    <?php
    // ********* If the Submit button was clicked do this.
    if (!empty($_POST['Submit'])) {

    // Put your post variables into varaibles
    $email $_POST['email'];
    $name $_POST['name'];

    // Joins all the variables into one    
    $message   "email: $email \n";
    $message  .= "Name: $name \n";

    // Settings for sending the email
    $headers   "From: Email from website \n";
    $headers  .= "Reply-To: $email";

    mail'your_email_address','Email from website',$message,$headers );

    exit( 
    "<br /><center><h2>Email sent<br /><br /><br />Thank you for your email I will reply as soon as I can.<br /><br />Anthony<br /></h2><br /><br /><a href=\"index.php\">Return to the website index page</a></center>");
        }

    // ***** Otherwise do this
    echo "<h2> Please use this form to contact us</h2><br />";
    ?>

    <form method="post" action="<?= $_SERVER['PHP_SELF']; ?>" >

    <p><input name="email" type="text" id="email" ><span class="required"> ( Required )</span></p>

    <p><input name="name" type="text" id="name" ><span class="required"> ( Required )</span></p>

    <p><input class="submitbutton" type="submit" name="Submit" value="Submit" /></p>
    </form>
    I appreciate that you must think me stupid but I know nothing of PHP.
    Sorry


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •