views:

45

answers:

4

hi there, I'm a newbee I've got a little problem with my php-script. I try to generate dynamic formulars with php. which works very good. the problem is, I want my data to be send to another funcion in another php-script. I gues its a problem with the syntax:

<?php .... <form action=\"<?php myfunction() ?>\" ... > ... ?> 

When I used it in a normal html site, it works fine:

<html> .... <form action="<?php myfunction() ?>" ... > ... </html>  

So I'm lokking for a way to bring it in my php-script.

when I try this:

<?php .... <form action=\"" . myfunction() . "\" ... > ... ?> 

the value won't be given to my 2nd php script

hope u have an idea, thank u guys, mirrow

A: 

a form's action determines the URL to which the form's data is sent to. if you want to send your data to another page, the action field should be a path to that php page. if you want it to go to the same page, you can add a hidden field describing what function to go to, and send it to a page that routes the form to the given function based on that field.

ozk
i need to give the values to that function, but as I said its in another .php, the thing wih the hidde field sounds like a good plan, unfortunately I have no idea how to do this. do you may have anexample?
mirrow
+1  A: 

I believe, what you want is impossible! You can't send form data directly to a php function.

You need something like this:

<form action="receiving.php" method="post"><!-- or method="get" -->
  <!-- your form code -->
</form>

Than you need the php of the name in the action attribute:

<?php
function your_form_processing_function($_POST) { // or $_GET
  // process data
}
?>
jigfox
ok I get it work with a little bit of all you guy advice, so thank you very much. but now I've a little other proble: I would like to save the url to a pic, a user can upload, in my database via a form. how do i have to wirte the POST variable for thisI have this input field.input name=\"bildb\" type=\"file\" /and a form-taghow do I get the file-url?
mirrow
+1  A: 

If you want to pass form data to function in another script, you must just call that script from the form:

<form action="secondscript.php">

And find a way to call your function, like:

secondscript.php:

...
    if ( isset( $_GET['somefield'] ) ) myfunction();

    function myfunction()
    {
    // do something with form data
    }
...
killer_PL
A: 

Use this format:

<?php
.....
?>

<form action="<?php myfunction() ?>">
...
...
</form>

<?php
....
?>
Abhijeet Pathak