Jump to content

php created Button to refer to a new page


JayDude

Recommended Posts

I am a newby using php as the backbone for my web design, with a help from phpFreeks, I have come along way in a short time.

 

Below is a short script of two buttons created with php, how can I use the buttons to link to a new web page (similar to using "href" in html)?

I would like to use the php created buttons to keep the general look and feel to my site the same through.

 

In advance, thank you for the support...

 

This is the part in my normal page that shows the buttons:

 

echo "<form action='processButtonsDdr.php' method='POST'>

<input type='submit' name='display_button'

value='homepage' />

<input type='submit' name='display_button'

value='new entry' />

 

This is a snippet from my two button process page:

 

<?php

if($_POST['display_button'] == "home page")

{

????????????????? // what do I enter in this area to point the button to another webpage?

}

else

{

?????????????????

}

?>

Link to comment
Share on other sites

I have tried what you stated, but not one of the buttons point me in the right direction.

 

Error Message: Website not found error:404

 

Here are the two headers:

 

header("Location: ../home/test.htm");  //from public_html/home/test.htm

 

and

 

header("Location: addDdr.php");  //in the same folder as process file

Link to comment
Share on other sites

That just a path issue relative to the page processing the code.  Understand also, you'll to have these header("location:"); lines above anything that might be sent to the browser and it should be followed by exit;

<?php
   if($_POST['display_button'] == "home page")
   {
      header("Location: test.htm"); 
exit;
   }
   else
   {
      header("Location: addDdr.php");
exit;
   }
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
    "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
etc.

Link to comment
Share on other sites

I just dont know what I'm doing wrong here, even copied your script snipped into the page, even deleted all non php script, so its only looking like the snippet you gave me, to no avail...

 

Is there a way not to use a process page, but rather do it within the original form?

Link to comment
Share on other sites

Make sure form values match.  Looks like you have "homepage" in your form and "home page" in processing.  I would also use isset() so values not posted don't throw errors.  Btw, method post in the form should be lower case to validate but should work regardless.  So instead of using and else statement I would just use an if statement for each line and wrap it all in an isset() statement.  You could also use a switch if want to look into that, but for now let's just get things working.

<?php
if (isset($_POST['display_button'])){
if($_POST['display_button'] == "homepage")
{
   header("Location: test.htm"); 
exit;
}
if($_POST['display_button'] == "new entry")
{
   header("Location: addDdr.php");
exit;
} 
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.