How can I accomplish the following.
For example lets say I already have a template that checks to see if the user has entered a link if not it will not display the link template if so display the link template?
How can I accomplish the following.
For example lets say I already have a template that checks to see if the user has entered a link if not it will not display the link template if so display the link template?
<?php
$enteredLink = isset( $_POST['enteredLink'] ) ?1:0;
if ( $enteredLink ) {
?>
<a href="<?php echo htmlentities($_POST['enteredLink']);?>">link</a>
<?php
}
?>
You need to set a variable to a boolean, use an if statement and if it was entered, just output anything, otherwise don't.
The basics are:
<?PHP
if(isset($_REQUEST['supplied_link']))
{
// do something
}
else
{
// do another thing
}
However, it is very important to actually validate that link in some manner, particularly to ensure that it is not script code but is, in fact, a link. I chose $_REQUEST because it handles both POST and GET, but you could use $_POST as meder described.
In terms of validating, if you're using PHP 5, you can just use strpos to look for http:// at the front. Remember, in this case, the return value would be 0 (zero) for the desired match and either FALSE or > 0 for a failure. You could do a lot more than this (such as validating the URL against DNS, Spam blockers, etc), but this is the bare minimum.