Web Analytics Made Easy -
StatCounter PHP and HTML form mismatch, please can you help - CodingForum

Announcement

Collapse
No announcement yet.

PHP and HTML form mismatch, please can you help

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • PHP and HTML form mismatch, please can you help

    PHP and HTML form mismatch, please can you help.

    Hi, I am trying to get a form on an HTML page to work with PHP for the first time but am going wrong somewhere.

    Think it may be an issue with the ID's but am not completely sure.

    Am expecting a return of Name, Email address. Telehone number and Postcode.

    I would appreciate any help.

    Thanks in advance for any help.

    HTML
    Code:
      
    <form class="form" id="form1">
    	
          <p class="name">
            <input name="name" type="text" class="validate[required,custom[onlyLetter],length[0,50]] text-input" id="name" />
            <label for="name">Name</label>
          </p>
    	  
          <p class="email">
            <input name="email" type="text" class="validate[required,custom[email]] text-input" id="email" />
            <label for="email">E-mail</label>
          </p>
    	  
          <p class="web">
            <input name="web" type="text" id="web" />
            <label for="web">Telephone</label>
          </p>
    	  
          <p class="text">
    	  <input name="text" type="text" id="text" />
            <label for="text">Postcode</label>
          </p>
    	  
          <p class="submit">
            <input type="submit" value="Send" />
          </p>
    	  </form>
    PHP
    Code:
    <?php
    
    $name = $_POST['name']; // contain name of person
    $email = $_POST['email']; // Email address of sender 
    $web = $_POST['web']; // Your website URL
    $body = $_POST['text']; // Your message 
    $receiver = "[email protected]" ; // hardcorde your email address here - This is the email address that all your feedbacks will be sent to 
    if (!empty($name) & !empty($email) && !empty($body)) {
        $body = "Name:{$name}\n\nE-mail:{$email}\n\nTelephone:{$web}\n\nPostcode:{$body}";
    	$send = mail($receiver, 'Contact Form Submission', $body, "From: {$email}");
        if ($send) {
            echo 'true'; //if everything is ok,always return true , else ajax submission won't work
        }
    
    }
    
    ?>

  • #2
    hi, well firstly you dont have an action or method on your form.

    the action tells it where to go to process the input, and the method tells it what method to use.

    like this

    Code:
    <form class="form" id="form1" method="POST" action="yourfilename.php">
    also remember you can test your data on the php side by using this, if will give you the POST array

    PHP Code:

    echo "<pre>";
    print_r($_POST);
    exit;  
    //i always exit when i am testing but it is up to you 
    if you want to show individual posts then you can use

    PHP Code:

    echo "<pre>";
    echo 
    $_POST['form_input_name']; //use your form input name here 
    exit; i always exit when i am testing but it is up to you 
    also remember you dont want to just save your POST data directly to the db. always filter it first, one way is to use mysql_real_escape_string depending on your data of course.
    Last edited by durangod; Sep 8, 2011, 08:53 AM.
    I am not crazy, my computer had me checked but its on dialup and im still waiting for results :)
    A good way to remember objects from arrays is you shoot objects with arrows Example: $name->id; then Arrays are $name['id'];
    durangod is short for durango dave

    Comment


    • #3
      Thanks for the reply durangod.

      The original code below seems to work absolutely fine when I try it on my server without adding a method or action so I don't quite understand why I am getting an email returned to me when I test it.

      What I am trying to acheive is to take the 'name', 'email', 'web' and 'text' fields in the exisiting PHP/HTML below and change them to 'name', 'email', 'telephone' and 'postcode'.

      Getting a bit stuck here I think.

      Code:
      if (!empty($name) & !empty($email) && !empty($body)) {
          $body = "Name:{$name}\n\nWebsite :{$web}\n\nComments:{$body}";
      	$send = mail($receiver, 'Contact Form Submission', $body, "From: {$email}");
          if ($send)
      Original code I am trying to update below.

      Thanks again in advance.

      PHP
      Code:
      <?php
      
      $name = $_POST['name']; // contain name of person
      $email = $_POST['email']; // Email address of sender 
      $web = $_POST['web']; // Your website URL
      $body = $_POST['text']; // Your message 
      $receiver = "[email protected]" ; // hardcorde your email address here - This is the email address that all your feedbacks will be sent to 
      if (!empty($name) & !empty($email) && !empty($body)) {
          $body = "Name:{$name}\n\nWebsite :{$web}\n\nComments:{$body}";
      	$send = mail($receiver, 'Contact Form Submission', $body, "From: {$email}");
          if ($send) {
              echo 'true'; //if everything is ok,always return true , else ajax submission won't work
          }
      
      }
      
      ?>

      HTML
      Code:
      <div id="wrapper">
        <div id="form-div">
          <form class="form" id="form1">
            <p class="name">
              <input name="name" type="text" class="validate[required,custom[onlyLetter],length[0,100]] text-input" id="name" value="My Name" />
              <label for="name">Name</label>
            </p>
            <p class="email">
              <input name="email" type="text" class="validate[required,custom[email]] text-input" id="email" value="[email protected]" />
              <label for="email">E-mail</label>
            </p>
            <p class="web">
              <input type="text" name="web" id="web" />
              <label for="web">Website</label>
            </p>
            <p class="text">
              <textarea name="text" class="validate[required,length[6,300]] text-input" id="comment">Hello world</textarea>
            </p>
            <p class="submit">
              <input type="submit" value="Send" />
            </p>
          </form>
      
        </div>

      Comment


      • #4
        oh ok im guessing the reason you dont need a method or action is that ajax is using that div to process that for you. I know squat about ajax ok just fyi, but that seems to be logical. Honestly im not sure why your having to use ajax you can do it all thru php and html.

        but lets take a stab at this.

        you start by changing the input names and var names to match what you want, you can always convert them in the php but it becomes confusing to say for example input name text and then grab it as postcode.

        so the first thing is you need to change your form to reflect the names you want to use. so in other words have the input names in the form as

        Code:
          'name', 'email', 'telephone' and 'postcode'
        as far as the php goes

        checking the values

        PHP Code:

        if (!empty($name) && !empty($email) && !empty($body)) {
            
        $body "Name:{$name}\n\nWebsite :{$web}\n\nComments:{$body}";
            
        $send mail($receiver'Contact Form Submission'$body"From: {$email}");
            if (
        $send
        i corrected and added the other & to the first section it was missing. You do realize that all of those have to be true for it to process. also that if there is a space in there, it will not be false. Because a space is not empty. You also do not have an else if it returns false.

        so why dont we start with the form first.. but question first.
        do you really need to use ajax. are you open to do this thru php and html only?
        I am not crazy, my computer had me checked but its on dialup and im still waiting for results :)
        A good way to remember objects from arrays is you shoot objects with arrows Example: $name->id; then Arrays are $name['id'];
        durangod is short for durango dave

        Comment


        • #5
          i have a dr appointment and need to leave in a few min, im sure someone will step up here if not ill check and help you when i get back ok.
          I am not crazy, my computer had me checked but its on dialup and im still waiting for results :)
          A good way to remember objects from arrays is you shoot objects with arrows Example: $name->id; then Arrays are $name['id'];
          durangod is short for durango dave

          Comment


          • #6
            Thanks a lot for getting back in touch durangod

            Thanks a lot for getting back in touch durangod, I really appreciate it.

            To be honest I know little about PHP but the form was a really nice out of the box solution which I was keen to use.

            It did work as was but I was finding it a little difficult to customise.

            I will try your amends and see how I get on.

            Thanks again.

            All the best.

            Comment

            Working...
            X
            😀
            🥰
            🤢
            😎
            😡
            👍
            👎