Page 1 of 1

nested form actions ?

Posted: Thu Nov 13, 2003 2:46 pm
by vertigo
Hello
I have text input field, and i want to "connect" to that field two actions (submit's), so each of these two scripts can read from that field. How can i do that ?

Thanx again :)

Posted: Thu Nov 13, 2003 3:01 pm
by JAM
Like this?

Code: Select all

function a($var) { 
 echo $var; 
}
function b($var) { 
 echo $var; 
}

if (!empty($_POST['foo']) and strlen($_POST['foo']) > 0) {
 a($_POST['foo']);
 b($_POST['foo']);
}
(Coffeebreak, no time to verify that I wrote correctly.)

two buttons

Posted: Fri Nov 14, 2003 1:05 am
by vertigo
but i need to have two buttons on my page, and each script do different things but each script need data from the same text input field.
Two buttons needed....


Thanx

how to get submit value ?

Posted: Fri Nov 14, 2003 1:26 am
by vertigo
Hello again:)
I tried to make in html:

<form action=script.php method=post>
.....some fields.....
<input type=submit value=val1>
<input type=submit value=val2></form>

How can i in script.php check if i pressed button val1 or val2 ?

Thanx

Posted: Fri Nov 14, 2003 1:34 am
by Paddy
Ok, so you have a file called file.php

Your form code will look like this

Code: Select all

&lt;form method="post" action="file.php"&gt;
    &lt;input type="text" name="sometext"&gt;
    &lt;input type="submit" name="button1" value="Button 1"&gt;
    &lt;input type="submit" name="button2" value="Button 2"&gt;
&lt;/form&gt;
Then at the top of the page you put your php

Code: Select all

<?php
    $sometext  = (isset($_POST['sometext'])?$_POST['sometext']:"");
    $button1  = (isset($_POST['button1'])?$_POST['button1']:"");
    $button2  = (isset($_POST['button2'])?$_POST['button2']:"");

    if ($button1)
    {
         //do something to $sometext
    }
    else if ($button2)
    {
         //do something else to $sometext
    }
?>

Posted: Fri Nov 14, 2003 12:46 pm
by Weirdan
Paddy wrote:

Code: Select all

<?php
    $sometext  = (isset($_POST['sometext'])?$_POST['sometext']:"");
    $button1  = (isset($_POST['button1'])?$_POST['button1']:"");
    $button2  = (isset($_POST['button2'])?$_POST['button2']:"");

    if ($button1)
    {
         //do something to $sometext
    }
    else if ($button2)
    {
         //do something else to $sometext
    }
?>
Why not just:

Code: Select all

<?php
    if (@$_POST['button1'])
    {
         //do something to @$_POST['sometext']
    }
    else if (@$_POST['button2'])
    {
         //do something else to @$_POST['sometext']
    }
?>
Looks much more clear to me.