Calling PHP function from form action
7 posts
Page 1 of 1
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.
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!
On file which will be called, if no other forms call it, you can make
If multiple forms access the same file, you can add hidden field and then check what that field value is and call function
Code: Select all
For post method or put $_GET for get methodif($_POST) nameOfFunction();
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
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.
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!
add this on top above the html code
were you wanted to call it
Code: Select all
add this somewhere between your html code<?php
include 'includes/some_file.php';
?>
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
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
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.
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!
Code: Select all
your functions should have a return value.
<?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>
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;
}
?>
7 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023