Forms and PHP

windows

Guest
Is it possible to create a form with a button and then when you click the button in runs a function that was predefined in php?

an overly simplified example


<?php
function test()
{
echo "The Test Worked";
}
?>

<input type="button" value="Click Me" OnClick="test()">no since the onclick is javascript only. so that function has to be javascriptIs there a way that user interaction could make a php function run after the page has been initally drawn? What I'm trying to do is create a page that doesn't have to be submitted, or a "Get" link doesn't have to be followed in order for it to run a function in php with variables that have been gathered from a form on that page.no, it isnt possible
php is server side, meaning it is run only when the information is being sent from the server to the browser, it cant interact with anything after that. you have to use javascriptfor what reason do you want this?

I would go with scoutt's post - use javascript if the current page is to be changed without submitting information.

Otherwise, submit the information, and have the next page render according to how the information in the form has been filled out.

but i ask my question again - What are you trying to achieve? - we may be able to get a better answer for you.this is how i would do it..


<?php

function main() {
echo "<form method=\"post\" action=\"$PHP_SELF\">\n";
echo "<input type=hidden name=\"x\" value=\"test\">\n";
echo "<input type=\"submit\" value=\"Click Me\">\n";
}

function test() {
echo "Hello, This is a test!\n";
}

switch($x) {

case "main":
main();
break;

case "test":
test();
break;

default:
main();
break; }

?>

hope this is what you were looking for,

emby
 
Back
Top