Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Mar 2013
    Posts
    15
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Help with PHP form...thank you :-) (code)

    First Name:

    Last Name:

    Telephone Number:

    Email:

    Comments:

    Does anyone know how to make a simple form using these fields.

    Thank you for your help! God bless <><+
    Last edited by Marifran; 05-07-2013 at 07:51 AM.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    What's your actual question here? This isn't a forum for free coding services, its a forum to help identify problems with your code and provide methods to fix them. You haven't provided any code to comment on.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #3
    Regular Coder
    Join Date
    Jul 2010
    Location
    Sheffield
    Posts
    827
    Thanks
    93
    Thanked 18 Times in 18 Posts
    http://www.w3schools.com/php/php_forms.asp That will give you the basics of building a PHP form

  • #4
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    738
    Thanks
    20
    Thanked 85 Times in 85 Posts
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month

  • #5
    New Coder
    Join Date
    Mar 2013
    Posts
    15
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Oh im sorry i didn't post the [code]

    THIS IS THE HTML [CODE]

    <table width="450px"> <tr> <td valign="top"> <label for="first_name">First Name
    *</label> </td><td valign="top"> <input type="text" name="first_name" maxlength="50" size="30">
    </td></tr> <tr> <td valign="top""> <label for="last_name">Last Name *</label>
    </td><td valign="top"> <input type="text" name="last_name" maxlength="50" size="30">
    </td></tr> <tr> <td valign="top"> <label for="email">Phone Number*</label> </td><td valign="top">
    <input type="text" name="email" maxlength="80" size="30"> </td></tr> <tr> <td valign="top">
    <label for="comments">Comments *</label> </td><td valign="top"> <textarea name="comments" maxlength="1000" cols="25" rows="6"></textarea>
    </td></tr> <tr> <td colspan="2" style="text-align:center"> <input type="submit" value="Submit"></td></tr>
    </table>

    THIS IS THE PHP [CODE]

    <?php
    //--------------------------Set these paramaters--------------------------

    // Subject of email sent to you.
    $subject = 'Results from Contact form';

    // Your email address. This is where the form information will be sent.
    $emailadd = 'myemailaddress@aol.com';

    // Where to redirect after form is processed.
    $url = 'http://mywebsite.com/thankyou.htm';

    // Makes all fields required. If set to '1' no field can not be empty. If set to '0' any or all fields can be empty.
    $req = '0';

    // --------------------------Do not edit below this line--------------------------
    $text = "Results from form:\n\n";
    $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: '.$emailadd.'');
    echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
    ?>

  • #6
    New Coder
    Join Date
    Mar 2013
    Posts
    15
    Thanks
    2
    Thanked 0 Times in 0 Posts
    I don't want the fields to be (required)

    i hope i did this right and thanks again for the help

    have a blessed day :-)

  • #7
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    738
    Thanks
    20
    Thanked 85 Times in 85 Posts
    at the moment your script doesn't require any fields to be filled.

    do you want some but not all fields to be required?

    see these lines below
    PHP Code:
            //set to 1 for required or 0 for not required
        
    $required = array('first_name' => 0'last_name' => 0'email' => 1'comments' => 0); 
    PHP Code:
    <?php
    //    THIS IS THE PHP [CODE]
    if (isset($_POST['formsent'])){
    //--------------------------Set these paramaters--------------------------

        // Subject of email sent to you.
        
    $subject 'Results from Contact form';

        
    // Your email address. This is where the form information will be sent.
        
    $emailadd 'myemailaddress@aol.com';

        
    // Where to redirect after form is processed.
        
    $url 'http://mywebsite.com/thankyou.htm';

        
    //set to 1 for required or 0 for not required
        
    $required = array('first_name' => 0'last_name' => 0'email' => 1'comments' => 0);

    // --------------------------Do not edit below this line--------------------------
        
    $text "Results from form:\n\n";
        
    $space ' ';
        
    $line '
        '
    ;
        foreach (
    $_POST as $key => $value)
        {
        if (
    $required[$key] == '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: '.$emailadd.'');
    echo 
    '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
    }else{
        echo
    '
            <form method="post">
    <input type="hidden" name="formsent" value="yes">
    <table width="450px">
        <tr>
            <td valign="top"> <label for="first_name">First Name *</label> </td>
            <td valign="top"> <input type="text" name="first_name" maxlength="50" size="30"></td>
        </tr>
        <tr>
            <td valign="top"> <label for="last_name">Last Name *</label></td>
            <td valign="top"> <input type="text" name="last_name" maxlength="50" size="30"></td>
        </tr>
        <tr>
            <td valign="top"> <label for="email">Phone Number *</label> </td>
            <td valign="top"> <input type="text" name="email" maxlength="80" size="30"> </td>
        </tr>
        <tr>
            <td valign="top"> <label for="comments">Comments *</label> </td>
            <td valign="top"> <textarea name="comments" maxlength="1000" cols="25" rows="6"></textarea></td>
        </tr>
        <tr>
            <td colspan="2" style="text-align:center"> <input type="submit" value="Submit"></td>
        </tr>
    </table>
    </form>
        '
    ;
    }
    ?>
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month


  •  

    Posting Permissions

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