www.webdeveloper.com
Page 1 of 3 123 LastLast
Results 1 to 15 of 38

Thread: Php?

  1. #1
    Join Date
    Apr 2003
    Location
    Nevada
    Posts
    411

    Php?

    Can PHP make forms?

  2. #2
    Join Date
    Jan 2003
    Location
    Texas
    Posts
    10,413
    Um, not sure what you mean by that. It can process them, but (X)HTML is the only way to make forms. But you can write HTML via PHP, like this:

    PHP Code:
    echo ('
           <form action="process.php" method="POST" name="processForm"><div>
             <input type="text" name="fieldName"><br>
             <input type="submit">
           </div></form>
    '
    ); 
    [J]ona

  3. #3
    Join Date
    Apr 2003
    Location
    Nevada
    Posts
    411
    does it actually send? not go to the mailto: command?

  4. #4
    Join Date
    Jan 2003
    Location
    Texas
    Posts
    10,413
    Originally posted by Jonathan
    does it actually send? not go to the mailto: command?
    Actually, it sends but isn't processed. What you're asking for is a PHP script that processes forms. Here's an example.

    PHP Code:
    <?PHP
    if(!isset($_GET["node"]) || $_GET["node"] != "process"){
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
       "http://www.w3.org/TR/html4/strict.dtd">
    <html lang="en">
    <head><title>Form Processing in PHP</title>
    <meta http-equiv="Content-Type" content="text/html; charset=8859-1">
    </head>
    <body>
    <form action="<?PHP echo $_SERVER['PHP_SELF']; ?>?node=process" method="POST"><div>
    <input type="text" name="fieldName" value="Enter anything you want!"><br>
    <input type="submit">
    </div></form>
    </body></html>
    <?
    } else {
    mail("you@yoursite.com""Subject - Email from your site""Someone submitted the form on your site. They put in this:\n\n".$_POST["fieldName"], "From: Your_site.com");
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
       "http://www.w3.org/TR/html4/strict.dtd">
    <html lang="en">
    <head><title>Form Processing in PHP</title>
    <meta http-equiv="Content-Type" content="text/html; charset=8859-1">
    </head>
    <body>
    <p>You emailed:</p>
    <p><? echo $_POST["fieldName"]; ?></p>
    </body></html>
    <? ?>
    [J]ona
    Last edited by Jona; 07-06-2003 at 01:17 AM.

  5. #5
    Join Date
    Apr 2003
    Location
    Nevada
    Posts
    411
    re-worded...

    If I were to put a php coding on my site for a form, would I be able to see the outcome of the form in my e-mail, if so... what would it look like?

  6. #6
    Join Date
    Jan 2003
    Location
    Texas
    Posts
    10,413
    Originally posted by Jonathan
    re-worded...

    If I were to put a php coding on my site for a form, would I be able to see the outcome of the form in my e-mail, if so... what would it look like?
    I've edited my post.

    [J]ona

  7. #7
    Join Date
    Apr 2003
    Location
    Nevada
    Posts
    411
    I am soryr, but I am new to all this PHP stuff... I don't ahve a clue what you are saying...

  8. #8
    Join Date
    Jan 2003
    Location
    Texas
    Posts
    10,413
    If you copy and paste everything I've posted (and edit the you@address.com part in the mail() function), and save it as "anything.php" and run it on your site, you'll see what the code does.

    [J]ona

  9. #9
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    You might want to use something like this: http://forums.webdeveloper.com/showt...9543#post48748

    Then, once you have that set up, just set up your form tag something like this:

    <form action="mailer.php" method="post">

    where mailer.php is the name you gave the script from the link above.

  10. #10
    Join Date
    Apr 2003
    Location
    Nevada
    Posts
    411
    3 things...

    • if(!isset($_GET["node"]) || $_GET["node"] != "process"){

      What does this mean?
    • How would I fit other stuff like a checkbox, textarea, etc... what would I have to do from this:

      mail("webmaster@crosspoint.org", "Subject - Feedback", "Someone submitted the form on your site. They put in this:\n\n".$_POST["fieldName"], "From: crosspoint.org");
    • Would I just type that echo $_POST[fieldname] again?


    AND how come there are 3 pages on one page?

    ----This is really helping... just to let you know

    PYRO---
    How do you work your php script?

  11. #11
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    Originally posted by Jonathan
    PYRO---
    How do you work your php script?
    Please ask a more specific question. I don't know what part you do not understand. What you do is take the script I linked to, change the info in the top to be what you want, save it as mailer.php (or anything with a .php extention) and link to it in your forms action.

  12. #12
    Join Date
    Jan 2003
    Location
    Texas
    Posts
    10,413
    The first if statement is a test to see which command to execute: display the form, or process the form? If the form hasn't been submitted, then you can't process it, but if the form has been submitted, then you can. So, instead of checking to see if(isset($_POST["fieldName"]), we check to see if the query string is nothing. If it is, display the HTML form, if it's not, process the form. That is why I have the action="thephpPage.php?node=process" on it. If I took that off, it wouldn't process the PHP, it'd just show the form again. This also explains the, "three pages on one page." (Which, actually, it's two pages. )

    Adding form elements is done in the same way the first one is done. You add HTML elements to the first part of the PHP code--the one that displays the form--and you name them whatever you like. Then you call them with $_POST["nameOfTheField"] and you can add them to your email and echo them to the next page at will. (This also answers your "third" question.)


    [J]ona

  13. #13
    Join Date
    Apr 2003
    Location
    Nevada
    Posts
    411
    How do I adjust what type of form items are on the form, or does it matter... Can I put as many items on there as I would like?

  14. #14
    Join Date
    Jan 2003
    Location
    Texas
    Posts
    10,413
    You can put as many form items as you like in there, and it will work. You can put any type of input in there, and it will work.

    [J]ona

  15. #15
    Join Date
    Apr 2003
    Location
    Nevada
    Posts
    411
    So all I have to do is put $_POST["nameOfTheField"] to make it show up on my form in my e-mail?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles