Solved

Looking for a PHP Button who calls a function

Posted on 2009-04-14
4
428 Views
Last Modified: 2013-12-12
Hi, i do have seperated HTML and PHP Content.

With the following php code

<?php
$fk ->jump(newpage.html)
?>

i can jump from page to page. But i would like to have a button and if it is click, jump is call.

I tried, but failed. Any Ideas?
0
Comment
Question by:easterbunny09
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 2

Expert Comment

by:Shodan82
ID: 24136379

<form action="<?=$_SERVER['PHP_SELF'];?>" method="post">
    <input type="button" name="submit" value="Submit">
</form>
 
// at top of the page put this:
 
<?php
// if the button is clicked
if(isset($_POST['submit']))
{
    // run your php function
    foo();
}
?>

Open in new window

0
 
LVL 6

Accepted Solution

by:
den4b earned 500 total points
ID: 24136385
There are 2 ways of doing this:
PHP + JavaScript:
Use PHP to print out JavaScript code that will redirect browser to another page, e.g. <script>window.location = 'http://your-new-url'</script> 
PHP + HTTP Headers:
Use PHP's header() function to send HTTP headers of a redirect, e.g. header('Location: http://your-new-url'). For this to work you would need to buffer the output, because header() function cannot be called after you started outputting from your PHP page.
Tell me which way you want to do it and I can give you a full example.
0
 
LVL 6

Expert Comment

by:den4b
ID: 24156131
I actually thought that within PHP code you needed functionality to break the execution of the code and redirect to another page. Now that I read it again, it seems that you needed something else. A little mistake on my side.

If you want a PHP function that will print an HTML button that will call another page once clicked, then you can use this code for your jump() function:


<?php
 
function make_jump_button($url, $title)
{
  $url = htmlspecialchars($url, ENT_QUOTES);
  $title = htmlspecialchars($title, ENT_QUOTES);
  echo "<button style=\"cursor: pointer\" onclick=\"window.location='{$url}'\">{$title}</button>";
}
 
make_jump_button('http://www.example.com/', 'test link');
 
?>

Open in new window

0

Featured Post

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

635 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question