View Full Version : help with FORMS and FUNCTIONS
TwitterRooms
01-17-2012, 09:52 PM
Hi guys simple question this form:-
<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
<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:p
djr33
01-18-2012, 01:40 AM
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.
Dunya
01-18-2012, 05:35 AM
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 :confused:
TwitterRooms
01-18-2012, 06:36 AM
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??
djr33
01-18-2012, 07:34 PM
Dunya, please post a new thread using this link:
http://dynamicdrive.com/forums/newthread.php?do=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.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.