WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
PHP Web Logs (BLogs)
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Submit Site
Forex Trading Online forex trading platform

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Newbie Notes #9 - Hyperlinking a post
Categories : PHP, Java Script, HTML and PHP, Beginner Guides Click here to Update Your Picture
Simon Booth
Date : Apr 23rd 2004
Grade : 3 of 5 (graded 2 times)
Viewed : 7851
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Simon Booth
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

NewbieNotes is a little series of tips for people who are new to PHP to give them a few handy tips that the more experienced of us use often

Quite often you'll want to use text links, possibly with some nice CSS effects, to link to another page rather than using a form's button or image submit way of doing things.

There are several reasons why you might not want to use a standard <a href="somewhere.php">Some text</a> invocation in your webpage.

The two most obvious reasons for not doing it this way.

Firstly you may not want the ugly and possibly abusable variable you're passing being shown in plain, you don't really want http://www.myserver.dom/somescript.php?user=fred&pass=pass displayed in the address bar after all.

Secondly if you're trying to send over 255 characters many web servers will get very upset, they don't like an address over 255 characters so sending a load of data in the URL just won't work.


An elegant and simple solution to this problem is to use a little JavaScript to fake a submit button being pressed when the user clicks on the link.

All you need is a form at the end of your HTML with as many hidden inputs as you desire replicating the contents of the information you want passed.

Usage Example

<form name="aform" action="somewhere.php" method="post">
<input type="hidden" name="firstName" value="<?php echo $firstName; ?>">
<input type="hidden" name="lastName" value="<?php echo $lastName; ?>">
<input type="hidden" name="section" value="0">
</form>


Note that it's important that you use a name tag with the hidden form!

The user will never see this form, and you can put as much information as you want in the hidden inputs of the form. Also note that there's no way of submitting the form (yet)

Going back to our original hyperlink we now modify it slightly so it now looks like this...

<a href="" onclick="return clickpost(<?php echo $param; ?>);">Some text</a>


The 'param' bit in the example above is just to illustrate what comes next and is completely optional, if you need them add then, if not, don't. If you're displaying a list of sections or something then param might be the section number or whatever. We'll use param to change the value of the 'section' hidden input in the hidden form.

Simply add a little JavaScript somewhere in the <head> ... </head> part of your page and we're done. The JavaScript would look something like this...

function clickpost(param)
  {
  document.forms.aform.elements.section.value = param;
  document.forms.aform.submit;
  return true;
  }


That's it. Your hyperlinks will now use the hidden form to do stuff and it'll use post rather than get so you have a nicer looking application without passing information in plain sight.

It should be noted that this is really handy when building up things like A-Z indexes and suchlike where the next page wants a record ID, you just use the $param trick and the page almost builds itself.



Pull Down Surfing - Surf on Change
Categories : Java Script, MySQL, HTML and PHP, PHP, Databases
Remote Scripting: send form POST data to a script and insert the results into a page without refreshing the page.
Categories : PHP, AJAX, HTML and PHP, Java Script
Newbie Notes #1 - Making a form return to itself
Categories : PHP, Beginner Guides, HTML and PHP
How to preset a text string in a textarea input field
Categories : HTML, HTML and PHP, PHP, Beginner Guides
Easy alert box pop-up function
Categories : PHP, Java Script, Beginner Guides
Form Submission Using Array's
Categories : PHP, HTML and PHP, Beginner Guides, Arrays
Simple PHP Form Field Generator
Categories : PHP, Beginner Guides, Form Processing, HTML and PHP
Dynamic generation of textboxes, select items etc in a table for use with databases applications, matrimonials and for job sites
Categories : PHP, HTML and PHP, Java Script
Kewl Date Example
Categories : PHP, HTML and PHP, Date Time, CSS, Beginner Guides
Tree Menu Dynamic (+Static) with Loading in Progress..
Categories : PHP, Java Script, HTML and PHP
OverEasy - PHP generated JavaScript to do mouseovers on your pages. Modify one file and one function does it all for you!
Categories : PHP, Java Script, HTML and PHP, MySQL
mySQL/PHP/search with multientry form and table output with colored rows
Categories : PHP, Beginner Guides, MySQL, HTML and PHP, Databases
Multiple Select box, Select multiple Items from Menu.List box
Categories : PHP, HTML and PHP, Beginner Guides
Local Time clock and Server time usign PHP and JavaScript
Categories : PHP, Java Script, Date Time, Beginner Guides
This PHP function creates dropdown select lists for time and date that you can change, outputs a 14 char MySQL timestamp in a text field
Categories : PHP, MySQL, Java Script, HTML and PHP
 Shiraz Esat wrote :1087
Be careful with some browsers (e.g. IE5.0):

&lt;a href="" onclick="return clickpost(&lt;?php echo $param; ?&gt;);"&gt;Some text&lt;/a&gt;

might not work, because the href="" `overrides` the onclick.

I use:
&lt;a style="cursor:hand" onclick="return clickpost(&lt;?php echo $param; ?&gt;);"&gt;Some text&lt;/a&gt;

So that we still get the rollover effect on the &lt;a&gt; tag and we make sure the onclick works.