Page 1 of 1
button vs link
Posted: Wed Apr 05, 2006 6:41 am
by maciek4
Buttons have names
Code: Select all
<input align="center" name="submit" type="submit" value="Submit">
and when you click on it you get redirected to another page. On another page you can refer to the name of the button
Code: Select all
if (isset ($_POST['submit']))
{do something;
}
What if I want to replace a button with a link.
Code: Select all
echo '<a href="'.$_SERVER['REQUEST_URI'].'">Edit</a>
How would I refer to this link on another page?
Posted: Wed Apr 05, 2006 6:46 am
by JayBird
Code: Select all
echo '<a href="'.$_SERVER['REQUEST_URI'].'action=edit">Edit</a>
Code: Select all
if (isset ($_GET['action']))
if($_GET['action'] == "edit") {
// edit something;
} else {
//do something else
}
}
Posted: Wed Apr 05, 2006 7:44 am
by maciek4
Pimptastic wrote:Code: Select all
echo '<a href="'.$_SERVER['REQUEST_URI'].'action=edit">Edit</a>
Code: Select all
if (isset ($_GET['action']))
if($_GET['action'] == "edit") {
// edit something;
} else {
//do something else
}
}
I have to go to commit.php so
add_new.php
Code: Select all
echo '<a href="commit.php" name="edit">Edit</a>';
commit.php
Code: Select all
<?php
if (isset ($_GET['edit'])) {
echo'<form action="add_new.php" method="POST" name="myform">
<TR><TD ALIGN="right" VALIGN="middle" width="40%"> Name:
</TD>
<TD ALIGN="right" valign="middle"><input name="name" size="27" type="text" value="'.$_POST['name'].'"> </TD>
</TR>
<TR><TD ALIGN="right" VALIGN="middle">Description: </TD>
<TD ALIGN="right"><textarea name="desc" rows="5">'.$_POST['desc'].'</textarea>
</TD>
</TR>
<TR>
<TD colspan="2" align="center"><center><input align="center" name="submit" type="submit" value="submit"></center>
</TD>
</TR>
</form>';
}
?>
goes back to commit.php but no values are in the fields
Posted: Wed Apr 05, 2006 8:22 am
by maciek4
I partially solved it but still, it aint working like it should, because I want those values $_POST['name'] and $_POST['desc'] to appear in the fields in commit.php. When I click 'Edit' button I go back to commit.php but the form is empty.
add_new.php
Code: Select all
echo '<a href="commit.php?edit" name="edit">ZmieƱ</a>';
commit.php
Code: Select all
<?php
if (isset ($_GET['edit']) && isset ($_POST['name']) || isset ($_POST['desc'])) {
echo'<form action="add_new.php" method="POST" name="myform">
<TR><TD ALIGN="right" VALIGN="middle" width="40%"> Name:
</TD>
<TD ALIGN="right" valign="middle"><input name="name" size="27" type="text" value="'.$_POST['name'].'"> </TD>
</TR>
<TR><TD ALIGN="right" VALIGN="middle">Description: </TD>
<TD ALIGN="right"><textarea name="desc" rows="5">'.$_POST['desc'].'</textarea>
</TD>
</TR>
<TR>
<TD colspan="2" align="center"><center><input align="center" name="submit" type="submit" value="submit"></center>
</TD>
</TR>
</form>';
}
?>
Posted: Wed Apr 05, 2006 8:25 am
by Benjamin
Google "Javascript submit form link" for plenty of examples.
Posted: Wed Apr 05, 2006 8:37 am
by maciek4
agtlewis wrote:Google "Javascript submit form link" for plenty of examples.
dont know nothing about javascript but I will try. Cant it be done in php though?