PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
maciek4
Forum Commoner
Posts: 29 Joined: Tue Apr 04, 2006 8:17 am
Post
by maciek4 » Wed Apr 05, 2006 6:41 am
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?
JayBird
Admin
Posts: 4524 Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:
Post
by JayBird » Wed Apr 05, 2006 6:46 am
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
}
}
maciek4
Forum Commoner
Posts: 29 Joined: Tue Apr 04, 2006 8:17 am
Post
by maciek4 » Wed Apr 05, 2006 7:44 am
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
maciek4
Forum Commoner
Posts: 29 Joined: Tue Apr 04, 2006 8:17 am
Post
by maciek4 » Wed Apr 05, 2006 8:22 am
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>';
}
?>
Benjamin
Site Administrator
Posts: 6935 Joined: Sun May 19, 2002 10:24 pm
Post
by Benjamin » Wed Apr 05, 2006 8:25 am
Google "Javascript submit form link" for plenty of examples.
maciek4
Forum Commoner
Posts: 29 Joined: Tue Apr 04, 2006 8:17 am
Post
by maciek4 » Wed Apr 05, 2006 8:37 am
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?