HTML Form to PHP help

Discussion in 'HTML & Website Design' started by alicattt, Jul 19, 2007.

  1. #1
    I've set up a form in dreamweaver that sends through PHP to my email.

    What do i need to change so that the email shows descriptive field names i.e. name, surname... etc, as opposed to textfield, textfield 2 etc.

    my form code is:

    <table width="800" height="537" border="3" align="center" cellpadding="0" cellspacing="0">
    <tr>
    <td width="350">&nbsp;</td>
    <td rowspan="3">&nbsp;</td>
    </tr>
    <tr>
    <td height="252"><form id="form1" name="form1" method="post" action="/sendform.php">
    <table width="350" height="154" border="0" cellpadding="0" cellspacing="0">
    <tr>
    <td width="106" height="20"><div align="right"><span class="style2">Name</span></div></td>
    <td width="244"><label><input name="textfield" type="text" id="textfield" /></label></td>
    </tr>
    <tr>
    <td height="20"><div align="right"><span class="style2">Surname</span></div></td>
    <td><input name="textfield2" type="text" id="textfield2" /></td>
    </tr>
    <tr>
    <td height="20"><div align="right"><span class="style2">Email</span></div></td>
    <td><input name="textfield3" type="text" id="textfield3" /></td>
    </tr>
    <tr>
    <td height="65"> <div align="right"><span class="style2">Description of Requirements </span></div></td>
    <td><textarea name="textfield4" rows="4" id="textfield4"></textarea></td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td><input type="submit" name="Submit" value="Submit" />
    <input name="Reset" type="reset" id="Reset" value="Reset" /></td>
    </tr>
    </table>
    </form>
    </td>
    </tr>
    <tr>
    <td bgcolor="#FFCCFF">&nbsp;</td>
    </tr>
    </table>


    And my PHP code is this:

    <?php
    $subject = 'Results from Good Planet Design';

    $emailadd = 'andersonmusic@btinternet.com';

    $url = 'http://www.goodplanetdesign.com/thankyou.html';

    $req = '0';

    $text = "Results from form:\n\n";
    $email = $_POST['textfield3'] ;
    $space = ' ';
    $line = '
    ';
    foreach ($_POST as $key => $value)
    {
    if ($req == '1')
    {
    if ($value == '')
    {echo "$key is empty";die;}
    }
    $j = strlen($key);
    if ($j >= 20)
    {echo "Name of form element $key cannot be longer than 20 characters";die;}
    $j = 20 - $j;
    for ($i = 1; $i <= $j; $i++)
    {$space .= ' ';}
    $value = str_replace('\n', "$line", $value);
    $conc = "{$key}:$space{$value}$line";
    $text .= $conc;
    $space = ' ';
    }
    mail($emailadd, $subject, $text, 'From: '.$email.'');
    echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
    ?>

    Can anyone help?

    Thanks

    C
     
    alicattt, Jul 19, 2007 IP
  2. lucozade111

    lucozade111 Peon

    Messages:
    1,361
    Likes Received:
    47
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Change <textarea name="textfield4" rows="4" id="textfield4"> to <textarea name="DESCRIPTION HERE" rows="4" id="textfield4">
     
    lucozade111, Jul 19, 2007 IP
  3. iNTaYkE

    iNTaYkE Active Member

    Messages:
    259
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    73
    #3
    ^ same thing with the inputs, just update all of the name="<NAME HERE>"
     
    iNTaYkE, Jul 19, 2007 IP
  4. alicattt

    alicattt Peon

    Messages:
    15
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    great thanks people, that seems to work except for textfield 2, i've changed it to "surname" but still comes through as textfield 2?

    any ideas, heres form code

    <form id="form1" name="form1" method="post" action="/sendform.php">
    <table width="350" height="154" border="0" cellpadding="0" cellspacing="0">
    <tr>
    <td width="106" height="20"><div align="right"><span class="style2">Name</span></div></td>
    <td width="244"><label><input name="name" type="text" id="textfield" /></label></td>
    </tr>
    <tr>
    <td height="20"><div align="right"><span class="style2">Surname</span></div></td>
    <td><input name="surname" type="text" id="textfield2" /></td>
    </tr>
    <tr>
    <td height="20"><div align="right"><span class="style2">Email</span></div></td>
    <td><input name="email" type="text" id="textfield3" /></td>
    </tr>
    <tr>
    <td height="65"> <div align="right"><span class="style2">Description of Requirements </span></div></td>
    <td><textarea name="description" rows="4" id="textfield4"></textarea></td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td><input type="submit" name="Submit" value="Submit" />
    <input name="Reset" type="reset" id="Reset" value="Reset" /></td>
    </tr>
    </table>
    </form>

    thanks again
     
    alicattt, Jul 19, 2007 IP