SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    Freelance Web Designer KeithMcL's Avatar
    Join Date
    Oct 1999
    Location
    Dublin, Ireland
    Posts
    1,125
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi fellow server side scripters

    I'm very new to PHP and am working on creating a form that uses PHP.

    Basically what i'm hoping to do is:
    • Check if the submit button has been pressed or not.
    • Check that a valid email address format has been entered.
    • If the submit button has not been pressed (ie. it's the first visit to the page) then produce the form fields.
    • If the form has been filled out and the page submitted, populate the appropriate areas with the details submitted.
    • Once all details have been verified as correct, submit the info again, but this time the script emails myself with the info and also emails the $email with the similar info but an extra paragraph or two and also reload the page with the submitted details, plus a thank you note.

    My questions are:
    • I should do this all on the same page or not?
    • How do I differenciate between the first submit button and the second one?
    • How should I setup the script to send 2 different emails to me and the person that filled out the form?

    If there is anything else you feel I should do with this script please post it here.

    I hope I explained myself clearly and concisely

    rgds,

  2. #2
    Freelance Web Designer KeithMcL's Avatar
    Join Date
    Oct 1999
    Location
    Dublin, Ireland
    Posts
    1,125
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oops...the thread title doesn't have anything to do with the post

    I must have got carried away when typing and ended up forgetting about what I was going to ask a the start.

    I also wanted to ask if I should define certain functions at the start of the script for the likes of check_submit and check_email to use further on in the script

  3. #3
    SitePoint Member
    Join Date
    Mar 2001
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    General way I do this is...

    like this. Call this samepage.php...

    <?php
    do {
    if (!isset($mode)) // mode wasn't set, print form
    break;
    if (!emailaddressvalid($email)) // you need to write this fun
    break;
    mailmessage($email); // ditto, this will email to the user
    header("location: otherpage.php"); // done, redirect
    }while (0);
    ?>
    <HTML>
    <BODY>
    <FORM action="samepage.php" method=GET>
    <INPUT type=hidden name=mode value=1>
    <input type=text name=email size=64>
    <input class=cFF type=submit value="OK">
    </FORM>
    </BODY>
    </HTML>


    RW


    ===========================================
    http://badblue.com
    Small footprint P2P web server for Windows,
    File-sharing, PHP, wireless apps & more
    ===========================================

  4. #4
    SitePoint Evangelist
    Join Date
    Feb 2000
    Location
    England
    Posts
    568
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    let me take some of this:

    1. Form actions.

    the way i do it is have a hidden field in the form, the 1st form created would be

    <form type="hidden" name="do" value="check">

    sort of thing and then for second one you would do

    <form type="hidden" name="do" value="email">

    Then your php script is going to have 3 sections like

    PHP Code:

    if (!$do) {

    print 
    the first form

    } elseif ($do == "check") {

    print 
    the checking form with variables from first

    } elseif  ($do == "email") {

    send emails
    display thank you note

    } else {

    major errorhow on earth did they get hereonly by typing in the query string do=sdfsdf or something

    display erorr message


    that is your setup.


    To confirm an email use the function

    PHP Code:
    function check_email ($str) {
    // returns 1 if a valid email, 0 if not

    if (ereg ("^.+@.+\\..+$"$str)) {
    return 
    1;
    } else {
    return 
    0;
     }

    then call it like:

    PHP Code:
    if (!check_email ($email)) {
    $submit 0;
    $email "<B>Invalid E-mail Address</b>";

    if you are only using it once it might not be worth doing it as a function but good practice.


    Emails:

    just do the code twice for sending an email once with your email, once with theres with different message and subject.

  5. #5
    SitePoint Enthusiast nguip's Avatar
    Join Date
    Apr 2001
    Location
    Malaysia
    Posts
    95
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm..

    I suggest that you go thru Kelvin's tutorial on building a database driven site using php and mysql.

    It should solve your problem
    Ngu I.P.
    Web Developer

  6. #6
    Freelance Web Designer KeithMcL's Avatar
    Join Date
    Oct 1999
    Location
    Dublin, Ireland
    Posts
    1,125
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by nguip
    Hmm..

    I suggest that you go thru Kevin's tutorial on building a database driven site using php and mysql.

    It should solve your problem
    I have read Kevins tutorial on PHP and MySQL along with the wrox book "Professional PHP Programming" and altough Kevins tutorial is extremely good, it's more geared towards setting up a joke of the day script.

    Thanks anyhow!

  7. #7
    SitePoint Evangelist
    Join Date
    Feb 2000
    Location
    England
    Posts
    568
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    did we help at all?

  8. #8
    Freelance Web Designer KeithMcL's Avatar
    Join Date
    Oct 1999
    Location
    Dublin, Ireland
    Posts
    1,125
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Absolutely


Bookmarks

Posting Permissions

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