Web form help [SIMPLE]

Discussion in 'Scripting & Programming' started by Daniel, May 22, 2009.

  1. Daniel

    Daniel Byte Poster

    236
    6
    25
    Hey guys,

    I've created a web form that allows users to enter required information at the end of a test, stuff like your name, a drop down menu and a comment box.

    As HTML and PHP arnt really my forte, how would I go about submitting this information to either a central server (everyone being on the LAN) or able to upload it to a URL either through FTP or a HTMLRequest?

    Or do I need to use PHP? Flicked through a PHP book, but its 300 pages and I kinda wanna just be able to submit this form rather than learning PHP as im doing 291 at the minute, aha, so yeah..

    Any input or an example would be brilliant!

    Code:
    <input id="saveForm" class="button_text" type="submit" name="submit" value="Submit" />
    Thats the submit button, can I just add something to send the information somewhere?

    MAYBE, just from index.html to like results.html?

    Cheers guys!

    EDIT: Realised this is in the wrong forum, can a Mod move please, thanks.
     
    Certifications: 70-270, 70-290, 70-291
    WIP: None, but learning SEO/SEM
  2. ThomasMc

    ThomasMc Gigabyte Poster

    1,507
    49
    111
    Hi Dan here is a little link that will get you started, you will need something at the other end thats going to do something with the data via php or asp and example of this is the newreply.php file of this forum in my address bar there is

    Code:
    newreply.php?do=newreply&noquote=1&p=296262
    
    this sends 3 variables to the newreply.php via the get method

    1) do=newreply
    2) noquote=1
    3) p=296262

    now there is something like <?php echo $_GET["Insert variable to read"]; ?> in newreply.php that will read the value on the other page and then does something with it.
     
    Certifications: MCDST|FtOCC
    WIP: MCSA(70-270|70-290|70-291)
  3. dmarsh
    Honorary Member 500 Likes Award

    dmarsh Petabyte Poster

    4,305
    503
    259
    Generally HTML forms are used to POST data to the action url of the form, its that simple.

    Something on the server end then reads the HTTP POST request and processes it.

    If you're studying for 291 why you trying to develop a web page ? Get back to work !
     
  4. Daniel

    Daniel Byte Poster

    236
    6
    25
    @ ThomasMc: Thanks very much mate!

    @ marsh: Haha, I'm working on a project for my company, I just wanted to see If I could input anything as our web developers are busy right now with a massover site overhaul. I one day hope to be fluent in all web languages, hopefully after the MCSA! I like to dabble to expose myself to as much as I can so then I can see if I take interest in it, like I have with HTML/CSS and PHP, then I will pursue them and learn them completely :biggrin.

    The more you learn, the more you earn!


    :biggrin
     
    Certifications: 70-270, 70-290, 70-291
    WIP: None, but learning SEO/SEM
  5. cpickering

    cpickering Bit Poster

    12
    0
    4
    PHP for a contact form is easy.. You should always use POST and never GET for forms when possible, as your can inject changes to the code/spam the hell out of the system..

    I'll post you some dead basic code for a contact form, using 1 page PHP so you dont need many pages :)
     
  6. cpickering

    cpickering Bit Poster

    12
    0
    4
    Place this at the top of the PHP page inside
    Code:
    <? ?>
    tags.. Yes I used shorthand, you could use
    Code:
    <?php
    if you wanted..

    PHP:
    // Contact US Form PHP Code
    // Carl Pickering 

    // Stops page from sending form when loaded
    if($_POST['action']=='send') {

    // define some variables first
    $send_to "[email protected]";
    $subject "Subject";

    // Pop-Up Txt
    $thank_you ="Thank you for enquiry, we will contact you back soon";

    $c_person $_POST['c_name'];
    $c_email $_POST['c_email'];
    $c_phone $_POST['c_phone'];
    $c_message $_POST['c_message'];

    // Build the message
    $message "The following person has sent information from the website\n\n";
    $message .= "Name: $c_person\n";
    $message .= "Telephone: $c_phone\n";
    $message .= "Email: $c_email\n";
    $message .= "Message: $c_message \n";
    $mailheaders "From: $c_person <$c_email> \n";
    $mailheaders .= "Reply-To: $c_person <$c_email>\n\n";

    // Simple but basic.. Now send the email
    mail($send_to$subject$message$mailheaders);

    print(
    " <script language=\"Javascript\"> alert('$thank_you'); </script> ");
    }  
    The form content itself

    HTML:
    <form action="contact.php" method="post" enctype="multipart/form-data" name="contact_us" id="form">
      <table cellpadding="0" cellspacing="0" border="0" width="100%">
        <tr>
            <td height="23" style="padding:2px 0px 0px 0px;" align="right" width="100%">Your Name:</td>
            <td><input name="c_name" type="text" class="input_2" id="c_name"></td>
        </tr>
        <tr>
            <td height="23" style="padding:2px 0px 0px 0px;" align="right" width="100%">Your Phone:</td>
            <td><input name="c_phone" type="text" class="input_2" id="c_phone"></td>
        </tr>
        <tr>
          <td height="23" style="padding:2px 0px 0px 0px;" align="right">Your email: </td>
          <td><input name="c_email" type="text" class="input_2" id="c_email"></td>
          </tr>
        <tr>
            <td height="23" style="padding:2px 0px 0px 0px;" align="right" width="100%">Message:</td>
            <td><textarea name="c_message" cols="3" rows="3" id="c_message"></textarea></td>
        </tr>
        <tr>
            <td width="100%"><input name="action" type="hidden" id="action" value="send"><input class="button_text" type="submit" name="submit" value="Submit" /></td>
            <td align="right" style="padding:5px 0px 0px 0px;"></td>
        </tr>
    </table>
    </form>        
    
    This is a very basic code, and yeah it could be ripped by people or changed to be better.. Its just a very basic code.. Abuse it/use it as you wish :)
     
  7. Daniel

    Daniel Byte Poster

    236
    6
    25
    I love you cpickering :biggrin! Man hug! :p
     
    Certifications: 70-270, 70-290, 70-291
    WIP: None, but learning SEO/SEM
  8. cpickering

    cpickering Bit Poster

    12
    0
    4
    Awww spanx! Hope it helps mate..

    Notice the first if statement in the PHP code, this ties into the hidden form variable in the HTML code.. :) Means the page is only rendered unless submitted.. Naturally change the form action to be what ever you call the page, or use the PHP code for PHP self
    PHP:
    $_SERVER['PHP_SELF'];
    by changing the form to be
    HTML:
    <form action="<? $_server['PHP_SELF']; ?>"....
     

Share This Page

Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.