Page 1 of 1

hyperlink commenters name on blog!

Posted: Tue Sep 04, 2007 3:24 pm
by andyb2
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I am not a PHP programmer.
I have a blog in which i dabble with code!!!!

In my blog I have a popup window for comments. The user has the option to enter a website in the form.

When you view the post with its comments each comment has the the persons name who made the comment. I would like to hyperlink the name of the person who comments with their website ONLY if they give one (i do not require it to be entered).

The input lines in the form are:

[syntax="html"]<input type="text" name="author" id="author" class="textarea" value="<?php echo $comment_author; ?>" size="28" tabindex="1" />
and

Code: Select all

<input type="text" name="url" id="url" value="<?php echo $comment_author_url; ?>" size="28" tabindex="3" />
I tried the following (and some variations) to no avail:[/syntax]

Code: Select all

<?php
$urlentered = comment_author_url();
if (!empty($urlentered))
echo '<span class="commentauthor"><a href="',comment_author_url(),'" target="_blank">', comment_author(), ' </a></span>';
else
echo '<span class="commentauthor">', comment_author(), ' </span>';
?>
Thanks for any help
Andy


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Tue Sep 04, 2007 6:45 pm
by califdon
I'm not entirely clear about what you want to do, but it sounds like you want something to happen based on what a user enters. That can't be done with PHP because PHP executes on the server, before the file is sent to the browser. Any user interaction must be done with client-side code, usually Javascript.

Posted: Tue Sep 04, 2007 9:11 pm
by andyb2
sorry for not explaining myself better.
No that is not what i want to happen.

I am sure you are familiar with the way blogs work.

A user enters comments relating to a post into a form. These are submitted. This info gets stored in a database.

Then at some other time when the post is viewed/requested by the users browser, the database gets accessed and html pages are created server side.
This html page will have a list of all comments made relating to this post

Now the form i have created allows the user to enter a website address. it is optional.

So when the html code is created server side, accessing the database, i want the name of the person who made the comment to be a hyperlink for the web address.
If the field for website is empty in the database then i do not want a hyperlink to be present in the html code.

The reason i provided the <input > tags in the initial post was to show the variable names used in the form.

hope that clarifies things a bit

Andy

Posted: Wed Sep 05, 2007 10:58 am
by andyb2
ok so i solved it.
There seems to be a built in function
comment_author_link() that does exactly this.
I just used that instead

sorry to waste peoples time