button vs link

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

Post Reply
maciek4
Forum Commoner
Posts: 29
Joined: Tue Apr 04, 2006 8:17 am

button vs link

Post 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?

User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post 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
    }
}
maciek4
Forum Commoner
Posts: 29
Joined: Tue Apr 04, 2006 8:17 am

Post 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:&nbsp;
</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:&nbsp;</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 »

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:&nbsp;
</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:&nbsp;</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>';  
    } 

?>
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

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 »

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?
Post Reply