Jump to content

php function from form?


RaythMistwalker

Recommended Posts

<form action='<? function(); ?>'>

 

I already know this doesn't actually work so does anyone know any way of calling a function that is on the SAME page using a form?

 

Nope. The action tag sends POST data, GET data, or calls a js event. AJAX will (easily) be required to send the POST/GET data to your PHP function, keeping it on the same page though. AJAX isn't too hard.

Link to comment
Share on other sites

[quote author=oni-kun link=topic=283612.msg1344773#msg1344773

Nope. The action tag sends POST data, GET data, or calls a js event. AJAX will (easily) be required to send the POST/GET data to your PHP function, keeping it on the same page though. AJAX isn't too hard.

 

HUH?

Nope.

The method determines how the form data is sent. The action is merely a link extended to the submit. The submit triggers the browser to either append the data to the action-url or pass it in the body of the request(what is returned) as determined by the method as modified by the type. Once the request is processed the action is the "link" the browser uses to contact the server and submit the request body to.

 

HTH

Teamatomic

Link to comment
Share on other sites

If you want call a PHP function when the form is submitted. Then you'll need to do something like this

 

<?php

function some_function()
{
    echo 'form submittted';
}

if(isset($_POST['submit']))
{
     // call function here
    some_function();
}

?>
<fom action="" method="post">
  SOME FIELD HERE
  <input type="submit" name="submit" value="Submit" />
</form>

Link to comment
Share on other sites

another small function question.

I know they are formatted as:

 

function name() {
}

or if i have a variable,

function name($var) {
}

 

Say it has 2 variables am i correct in saying it is done like,

function name($var1, $var2) {
}

and to call it would be

name($var1, $var2);

 

Also in the actual function declaration does it set the variables sent (say name(1, 2);) then would $var1 = 1 and $var2 = 2?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.