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
Moderator: General Moderators
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']);
}Code: Select all
<form method="post" action="file.php">
<input type="text" name="sometext">
<input type="submit" name="button1" value="Button 1">
<input type="submit" name="button2" value="Button 2">
</form>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: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 } ?>
Code: Select all
<?php
if (@$_POST['button1'])
{
//do something to @$_POST['sometext']
}
else if (@$_POST['button2'])
{
//do something else to @$_POST['sometext']
}
?>