Results 1 to 5 of 5

Thread: help with FORMS and FUNCTIONS

  1. #1
    Join Date
    Oct 2011
    Location
    London
    Posts
    41
    Thanks
    19
    Thanked 1 Time in 1 Post

    Smile help with FORMS and FUNCTIONS

    Hi guys simple question this form:-
    PHP Code:
    <html>
    <
    body>

    <
    form action="action.php" method="post">
    Name: <input type="text" name="fname" />
    Age: <input type="text" name="age" />
    <
    input type="submit" />
    </
    form>

    </
    body>
    </
    html
    and...action.php
    PHP Code:
    <html>
    <body>

    Welcome <?php echo $_POST["fname"]; ?>!<br />
    You are <?php echo $_POST["age"]; ?> years old.

    </body>
    </html>
    NOW... if i had 4 forms on my site would i need 4 "action.php" files one for each or can i put "functions" in the one and get the differant forms to call differant functions in action.php???

    P.S please keep it simple as i'm still learning

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Either way could work. If they are related, you could use if statements (or functions) to decide what action to do. But if they're unrelated, you probably should keep them separate. There's no reason to confuse things if you don't need to.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Jan 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Need help in the form

    Greetings ,
    First I am sorry to reply here with my question because I couldnot ask question and I did not find how to ask a new question. I am new to this website . I wish if someone can help me or direct me to answer my question.
    I created a reservation form in PHP and I was looking after the client click submit he or she will get a confirmation number and also I will get that confirmation too. please help me in that I will really apprecitate it
    again I am so sorry to ask here .
    Thank you
    Dunya

  4. #4
    Join Date
    Oct 2011
    Location
    London
    Posts
    41
    Thanks
    19
    Thanked 1 Time in 1 Post

    Default

    Quote Originally Posted by djr33 View Post
    Either way could work. If they are related, you could use if statements (or functions) to decide what action to do. But if they're unrelated, you probably should keep them separate. There's no reason to confuse things if you don't need to.
    could you show an exaple off how to get a form to call a function please cos the bit i get stuck on is "action="action.php"" where does the function fit??

  5. #5
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Dunya, please post a new thread using this link:
    http://dynamicdrive.com/forums/newth...newthread&f=11
    Look for the "new thread" image at the top of each forum, above the posts.

    ----

    The form would submit to the same page, action.php. You don't need to change that part.
    There are two ways you could use an if statement:
    1. You could check what kind of information has been sent. For example, if 'username' and 'password' were sent, then it must be a login. If not, maybe it's a comment, etc.
    2. You can use the form action to send extra information. Use action.php?type=1 and then check for $_GET['type']-- if that has a value of 1, then you can do one kind of action.
    Either way, it will be the receiving page that decides what to do with the information.

    But again, if you have two unrelated processes, it's best to keep them separate.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  6. The Following User Says Thank You to djr33 For This Useful Post:

    TwitterRooms (01-18-2012)

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
  •