Jump to content


Photo

Calling a function from a link


  • Please log in to reply
2 replies to this topic

#1 romio

romio
  • Members
  • PipPip
  • Member
  • 28 posts

Posted 30 March 2006 - 08:29 AM

This is my menu code on my index.php:
function menu_case($selected)
{
    switch($selected)
    {
        case 0:
            echo add_product_form();
            break;
        case 1:
            echo find_products();
            break;
        default:
            echo find_products();
            break;
    }
}
When the page loads I have find_products() as a default value, on the same page I have a "Add Product" which will link to a function, how can I do that?

I have tried doing this but I get an error:

<a href='<? menu_case(0) ?>' class='style10'>Add Product</a> | Add  Category<br><HR></td>

Note that my add_product_form() contains a form which be displayed on the same page.

#2 fooDigi

fooDigi
  • Members
  • PipPipPip
  • Advanced Member
  • 250 posts
  • LocationDuluth, Mn

Posted 30 March 2006 - 08:42 AM

i think you should return the value from that function:

function menu_case($selected)
{
switch($selected)
{
case 0:
$someVar = add_product_form();
}

return $someVar;
}
All your base are belong to us.

#3 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 30 March 2006 - 01:13 PM

Php runs on the server so cant be directly called from links (like javascript), but there are ways....

An example...
<?php

  if (isset($_GET['action'])) {
    switch ($_GET['action']) {
      case "foo":
        foo();
      break;
      case "bar";
        bar();
      break;
    }
  }

  function foo() {
    echo "this is foo\n";
  }

  function bar() {
    echo "this is bar\n";
  }

?>

<a href="?action=foo">call foo</a>
<a href="?action=bar">call bar</a>
Hope this helps.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users