www.webdeveloper.com
Results 1 to 5 of 5

Thread: onSubmit to run a php function

  1. #1
    Join Date
    May 2011
    Posts
    1

    onSubmit to run a php function

    Hi,

    On submitting a form does the ensuing function have to be javascript or can it also be a .php function?

    For example if i have a <form method= "POST" onSubmit="phpfunction(this);"

    and then later: <?php function phpfunction(){some function} ?>

    - Should I be able to run the php function when the form is submitted?
    - is it OK that the form is not within "<?php ?>"
    - what should go inside the parenthesis when defining the phpfunction?

    thanks

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,220
    PHP runs on the server, JavaScript runs on the browser after the PHP script is long since done and has sent its output to the browser. If you want onsubmit() to run a PHP function without/before actually submitting the form to the server, you'll need to use an AJAX implementation where a JavaScript XMLHttpRequest object calls a PHP file on the server, receives the response from the server and processes it accordingly.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Oct 2010
    Location
    Ohio
    Posts
    233
    Hey nog, do you know a good resource for stepping into ajax?
    ~Ryan
    www.rdennispallas.com <-- Personal Site, changing regularly cuz its ugly.

  4. #4
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,220
    Quote Originally Posted by Derokorian View Post
    Hey nog, do you know a good resource for stepping into ajax?
    Nothing special comes to mind. I think I started with the w3schools.com tutorial, and then just Googled things to fill in the blanks, so to speak. I have a sort of proof on concept page with all the source code you could take a look at, too: http://www.charles-reace.com/test/ajax/
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  5. #5
    how about on the form tag you just run the php file? something like

    Code:
    <form metho="post" action="myphpscript.php">
    ...
    </form>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles