Page 1 of 1
Call php function
Posted: Mon Sep 13, 2010 11:50 am
by alicefreak
Hello guys, I'm new to PHP. Please help me. I have two functions in myFunctions.php
1 is myName() and second one is yourName()
Code: Select all
function myName()
{
echo "my name is this.";
}
function yourName()
{
echo "your name is that.";
}
and I have two submit button. One is my and another is you. When user click on my button. then myName() function is called and when user click on you then yourName() function is called.
Please help me. Thanks
Re: Call php function
Posted: Mon Sep 13, 2010 12:18 pm
by bradbury
put this in a separate php document (linkto.php) in this example
Code: Select all
fucntion myName($name) {
$name = $_POST['name'];
echo $name;
}
HTML
------
<form name="whatever" method="post" action"linkto.php">
<input type="text" name="name"id="name">
<input type="submit" name="Submit" value="Whatever you want displayed">
Hope this makes sense and you can apply this to your other function
Re: Call php function
Posted: Mon Sep 13, 2010 1:15 pm
by AbraCadaver
You can get fancier, but in general:
Code: Select all
<form method="post">
<input type="submit" name="submit" value="my">
<input type="submit" name="submit" value="you">
</form>
<?php
if(isset($_POST['submit'])) {
switch($_POST['submit']) {
case 'my':
myName();
break;
case 'you':
yourName();
break;
}
}
function myName()
{
echo "my name is this.";
}
function yourName()
{
echo "your name is that.";
}
Re: Call php function
Posted: Mon Sep 13, 2010 4:27 pm
by califdon
alicefreak wrote:Hello guys, I'm new to PHP. Please help me. I have two functions in myFunctions.php
1 is myName() and second one is yourName()
Code: Select all
function myName()
{
echo "my name is this.";
}
function yourName()
{
echo "your name is that.";
}
and I have two submit button. One is my and another is you. When user click on my button. then myName() function is called and when user click on you then yourName() function is called.
Please help me. Thanks
Separate in your mind the concepts of a
form and a
function. They are two unrelated parts of PHP. All a function does is return a value to somewhere else in the same script that calls the function. A form is the "wrapper" for a bunch of data input elements and when its submit button is clicked, it sends data to another script (or itself, if you put the right logic into it), so that it can recover the form data from either the $_POST or $_GET global array, as specified in the form tag. Don't get forms confused with functions.
Re: Call php function
Posted: Wed Sep 15, 2010 2:02 pm
by alicefreak
thanks for my help.
