Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Perform Function when...

  1. #1
    Join Date
    Jan 2007
    Location
    The stage
    Posts
    568
    Thanks
    23
    Thanked 6 Times in 6 Posts

    Default Perform Function when...

    I was wondering if PHP can perform a function when a link, button, or something is pressed...
    Heres what I want todo...
    Heres the HTML page code *its still in development stages but who really cares...*

    PHP Code:
    <html>
    <head>
    <!-- Style Stuff -->
    </head>
    <body>
    <table>
    <tr>
    <td>Menu:
    <ul class="menu">
    <li><a href="Tutorial/1/Introduction/" target="phpincludediv">Intro to PHP</li>
    <li><a href="Tutorial/2/Introduction/" target="phpincludediv">What you need to run PHP</li>
    ...
    </ul></td>
    <td>Tutorial Below:
    <?php 
    //Stuff here that says:
    //If link going to or named "url/blank" then do this...
    include("Tutorial/1/Introduction/index.php");
    //Else
    include("News/new.php");
    ?>
    </td>
    </tr>
    </table>
    </body>
    </html>

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    No. PHP scripts are run at request time: they can only respond to request data. If you want to pass data to a PHP script, you have to either submit a form to the PHP script in question, in which case the form data is passed along with the request and available to the script in the $_GET or $_POST arrays (or the $_REQUEST array, which is a combination of $_GET, $_POST and $_COOKIE) or use Javascript to process the event and display the result, possibly using the XMLHttpRequest object to retrieve the data from the PHP script. Note, however, that this usually involves some fairly involved Javascript, and requires careful and elegant design to be accessible.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Jan 2007
    Location
    The stage
    Posts
    568
    Thanks
    23
    Thanked 6 Times in 6 Posts

    Default

    OK... thanks man...
    I can't do it, cuz my client won't accept any javascript *he hates it...* same here...

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Javascript is actually a fairly decent language. What it is is very flexible, and thus open to abuse. Most of the time, bad Javascript code stems from bad design patterns (like writing a Javascript function without a pure HTML/server-side backup), rather than actual language flaws. Used properly, it can dramatically enhance a site, without losing any accessibility.

    Either way, the form submission route is still open to you.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Jan 2007
    Location
    The stage
    Posts
    568
    Thanks
    23
    Thanked 6 Times in 6 Posts

    Default

    k... but my client still won't accept any javascript...

  6. #6
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Javascript was only one option of two that I gave you. I was discussing Javascript purely as an aside, and on that note alone you should talk to your client about this preference. Practically, in terms of your project, the form submission method will be fine and Javascript is entirely unnecessary, although it could be used to enhance the interface.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  7. #7
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    (or the $_REQUEST array, which is a combination of $_GET, $_POST and $_COOKIE)
    it also contains variables of $_SERVER

  8. #8
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,156
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    SERVER is not included. (Nor is SESSION.)

    Quote Originally Posted by php.net
    Note: Prior to PHP 4.3.0, $_FILES information was also included in $_REQUEST.

    An associative array consisting of the contents of $_GET, $_POST, and $_COOKIE.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  9. #9
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    oops, okay its not. learn something new every day. thanks mate

  10. #10
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,156
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Indeed. When I read your post, I was unsure, so I wanted to check it. I was also thinking that the SESSION array was included.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •