JayDude Posted March 27, 2012 Share Posted March 27, 2012 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 https://forums.phpfreaks.com/topic/259806-php-created-button-to-refer-to-a-new-page/ Share on other sites More sharing options...
seanlim Posted March 27, 2012 Share Posted March 27, 2012 PHP header redirect? header("Location: new_page_here.php"); Link to comment https://forums.phpfreaks.com/topic/259806-php-created-button-to-refer-to-a-new-page/#findComment-1331546 Share on other sites More sharing options...
JayDude Posted March 27, 2012 Author Share Posted March 27, 2012 Thanks for the help seanlim Link to comment https://forums.phpfreaks.com/topic/259806-php-created-button-to-refer-to-a-new-page/#findComment-1331557 Share on other sites More sharing options...
JayDude Posted March 27, 2012 Author Share Posted March 27, 2012 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 https://forums.phpfreaks.com/topic/259806-php-created-button-to-refer-to-a-new-page/#findComment-1331565 Share on other sites More sharing options...
seanlim Posted March 27, 2012 Share Posted March 27, 2012 try using a absolute URL instead? i.e. header("Location: http://yousitehere.com/home/test.htm"); Link to comment https://forums.phpfreaks.com/topic/259806-php-created-button-to-refer-to-a-new-page/#findComment-1331569 Share on other sites More sharing options...
JayDude Posted March 27, 2012 Author Share Posted March 27, 2012 still not working, here is the complete script from the process page: (error:404 web page not found) <?php if($_POST['display_button'] == "home page") { header("Location: http://www.ad181.co.za/home/test.htm"); // with the www } else { header("Location: http://ad181.co.za/insert/addDdr.php"); // without the www } ?> Link to comment https://forums.phpfreaks.com/topic/259806-php-created-button-to-refer-to-a-new-page/#findComment-1331575 Share on other sites More sharing options...
Drummin Posted March 27, 2012 Share Posted March 27, 2012 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 https://forums.phpfreaks.com/topic/259806-php-created-button-to-refer-to-a-new-page/#findComment-1331579 Share on other sites More sharing options...
JayDude Posted March 27, 2012 Author Share Posted March 27, 2012 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 https://forums.phpfreaks.com/topic/259806-php-created-button-to-refer-to-a-new-page/#findComment-1331595 Share on other sites More sharing options...
Drummin Posted March 27, 2012 Share Posted March 27, 2012 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 https://forums.phpfreaks.com/topic/259806-php-created-button-to-refer-to-a-new-page/#findComment-1331598 Share on other sites More sharing options...
JayDude Posted March 27, 2012 Author Share Posted March 27, 2012 Thank you very much for the feedback, I can deffinately see other advantages and uses for AJAX Link to comment https://forums.phpfreaks.com/topic/259806-php-created-button-to-refer-to-a-new-page/#findComment-1331732 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.