How to Make a Button Run a Server-Side Script (HTML)

Create a button that invokes a PHP/Perl/Python/Ruby (etc) script


How to Make a Button Run a Server-Side Script (eg, a PHP, Perl, or Python Script) (HTML)

by Christopher Heng, thesitewizard.com

I was asked by a visitor how he could make a button, when clicked, run a script. In his case, he wanted the button to run a Python script, but you can make the button run any server-side script, such as PHP, Perl, Ruby, Ruby on Rails, Python, etc.

Prerequisites

Since my visitor merely wanted to invoke a script, without passing it any additional information, there are multiple ways to do it. This article describes two.

With a form

One way to cause a button to invoke a script is to put it within a form, since that is the latter's raison d'étre.

Let's say that you want your button to run a script called "http://www.example.com/do-something.php". The HTML code for this is:

<form method="get" action="http://www.example.com/do-something.php">
<button type="submit">Do something!</button>
</form>

When clicked, the web browser will issue a request for the specified URL (ie, web address), in this case, "http://www.example.com/do-something.php". This, in turn, will cause the web server to execute "do-something.php".

You should, of course, change the part that says "http://www.example.com/do-something.php" to point to the actual URL (ie, web address) of your script. Since you are not submitting any form content, you can leave the method attribute set to "get", although changing it to "post" will do no harm. (The attribute only affects the way the script is handed form data. Since there is no form data here, it makes no difference which method is used.)

With a simple link, dressed to look like a button

In fact, you don't even need a form if you only want to invoke a script without submitting any other information. You can code it as a simple hyperlink, like so:

<a href="http://www.example.com/do-something.php">Do something</a>

Then make the link look like a button using CSS. This can be done in any number of ways. See How to Create 3D Buttons Using CSS for more information. If you want to see an example of a link that looks like a button, just glance to the left column of this article (or in fact, any page on thesitewizard.com). All the buttons in that column are merely hyperlinks that have their appearance altered.

Copyright © 2019-2020 Christopher Heng. All rights reserved.
Get more free tips and articles like this, on web design, promotion, revenue and scripting, from https://www.thesitewizard.com/.

thesitewizard™ News Feed (RSS Site Feed)  Subscribe to thesitewizard.com newsfeed

Do you find this article useful? You can learn of new articles and scripts that are published on thesitewizard.com by subscribing to the RSS feed. Simply point your RSS feed reader or a browser that supports RSS feeds at https://www.thesitewizard.com/thesitewizard.xml. You can read more about how to subscribe to RSS site feeds from my RSS FAQ.

Please Do Not Reprint This Article

This article is copyrighted. Please do not reproduce or distribute this article in whole or part, in any form.

Related Articles

New Articles

How to Link to This Page

It will appear on your page as:

How to Make a Button Run a Server-Side Script (eg, a PHP, Perl, or Python Script) (HTML)





Home
Donate
Contact
Link to Us
No Spam Policy
Privacy Policy
Topics
Site Map

Getting Started
Web Design
Search Engines
Revenue Making
Domains
Web Hosting
Blogging
JavaScripts
PHP
Perl / CGI
HTML
CSS
.htaccess / Apache
Newsletters
General
Seasonal
Reviews
FAQs
Wizards

 

 
Free webmasters and programmers resources, scripts and tutorials
 
HowtoHaven.com: Free How-To Guides
 
Site Design Tips at thesitewizard.com
Find this site useful?
Please link to us.