/    Sign up×
Community /Pin to ProfileBookmark

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

    to post a comment
    PHP

    4 Comments(s)

    Copy linkTweet thisAlerts:
    @NogDogMay 17.2011 — 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.
    Copy linkTweet thisAlerts:
    @DerokorianMay 17.2011 — Hey nog, do you know a good resource for stepping into ajax?
    Copy linkTweet thisAlerts:
    @NogDogMay 17.2011 — Hey nog, do you know a good resource for stepping into ajax?[/QUOTE]

    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/
    Copy linkTweet thisAlerts:
    @papartsMay 27.2011 — how about on the form tag you just run the php file? something like

    [CODE]
    <form metho="post" action="myphpscript.php">
    ...
    </form>
    [/CODE]
    ×

    Success!

    Help @stanisikorski spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.16,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...