Calling PHP function from form action

7 posts Page 1 of 1
Contributors
User avatar
smashapps
Coding Guru
Coding Guru
Posts: 961
Joined: Tue Apr 05, 2011 8:41 am

Hello,

I need help with this one.

I am working with forms and php. When I submit the form my form's action is the php file. This works great.

I now want to call just a function from a php file from my html form. No code example should need to be given. If I wasn't clear let me know but please tell me if this is possible and how I can do it.

Thanks and 50cc to the correct answer.
My name is Tom | Visit my blog where I post new content every day! Tom's Daily Blog | MineCraft is awesome!
User avatar
Shim
VIP - Donator
VIP - Donator
Posts: 882
Joined: Wed Dec 14, 2011 5:02 am

Find my programs on Softpedia
Filip
Coding Guru
Coding Guru
Posts: 833
Joined: Wed Jan 05, 2011 3:59 pm

On file which will be called, if no other forms call it, you can make
Code: Select all
if($_POST) nameOfFunction();
For post method or put $_GET for get method

If multiple forms access the same file, you can add hidden field and then check what that field value is and call function
CodenStuff wrote:
Nope, it's just your sick and dirty mind. You sick twisted warped little pervo :D
User avatar
smashapps
Coding Guru
Coding Guru
Posts: 961
Joined: Tue Apr 05, 2011 8:41 am

Thanks guy but none of this is not what I am looking for. Those links have the php in the same file the form is in.

I have two files.

Root/index.php
Root/includes/some_file.php

In my index on the form action I would normally use action="includes/some_file.php"

But I don't want the file, I want some function out of that file.

To call a function from another file it is:

<?php include 'includes/some_file.php'; function_name(); ?>

But you can't use: action="<?php include 'includes/some_file.php'; function_name(); ?>" and you can't use action="function_name();" because the function is in a different file.
My name is Tom | Visit my blog where I post new content every day! Tom's Daily Blog | MineCraft is awesome!
User avatar
Dummy1912
VIP - Donator
VIP - Donator
Posts: 1969
Joined: Sat Aug 21, 2010 2:17 pm

add this on top above the html code
Code: Select all
<?php 
include 'includes/some_file.php';
 ?>
add this somewhere between your html code
were you wanted to call it
Code: Select all
<?php echo function_name; ?>
visit us on:


http://www.softpedia.com/get/System/Lau ... -Run.shtml
Check it out ! http://www.softpedia.com/publisher/I-A- ... 90017.html
Check it out ! http://www.softpedia.com/get/Desktop-En ... lock.shtml
User avatar
smashapps
Coding Guru
Coding Guru
Posts: 961
Joined: Tue Apr 05, 2011 8:41 am

I was in a discussion with a developer about this today and they suggested include the file and then call the function name. You're sort of correct but it would be action="<?php function_name(); ?>" we won't need echo we aren't echoing the function name we're calling the function name. I will try this method first and then if it's correct you've earned yourself 50cc.

Thanks.

EDIT:

None of these suggestions have worked. Still looking for an answer.
My name is Tom | Visit my blog where I post new content every day! Tom's Daily Blog | MineCraft is awesome!
User avatar
Scottie1972
Codenstuff Elite
Codenstuff Elite
Posts: 953
Joined: Thu Jan 14, 2010 5:48 am

Code: Select all
<?php 
include 'includes/some_file.php';

$form_function = function_FormAction();
$form_method = function_FormMethod();


?>

<form action="<?php echo $form_function; ?>" method="<?php echo $form_method; ?>">

</form>
your functions should have a return value.
Code: Select all
<?php
function function_FormAction() {
    $ret = "example.php?id=1";
    //or
    include('some_file.php');
    $ret = another_function_here();

    return $ret;
    //or
    echo $ret;
}
?>
Image
7 posts Page 1 of 1
Return to “Help & Support”