Solved

Looking for a PHP Button who calls a function

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

910 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now