Solved

Looking for a PHP Button who calls a function

Posted on 2009-04-14
4
424 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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PHP Web Development 6 69
php output utf-8 problem 6 51
how can I see the time difference in only seconds? 4 40
Load string Array from file 23 42
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
This article discusses four methods for overlaying images in a container on a web page
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

738 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