Forum Moderators: coopster

Message Too Old, No Replies

Custom link on a php button?

         

phpguy54

9:24 pm on Feb 12, 2008 (gmt 0)

10+ Year Member



Hey guys,

1st post here, hopefully I get to take part in many future discussions.

I have a question about something I want to do with a button.

Currently, I have a form setup that looks like this:

$fileurl = "<a href=\"index.php?q=file_download/quest/" . $fileid . "\">";

$cookie = explode("¦", $myCookie);
$fname = $cookie[0];
$lname = $cookie[1];

$deleteurl = "<a href=\"index.php?q=file_download/refresh/" . $fileid . "\">";

$output = "Thanks for your interest in XYZ<br><br> ";
$output .= "If you are ";
$output .= $fname;
$output .= "&nbsp;";
$output .= $lname;
$output .= "&nbsp;";
$output .= "please click on the following link to have the document delivered to your mailbox";
$output .= "&nbsp;";
$output .= $fileurl;
$output .= "send document</a>.";
$output .= "&nbsp;";
$output .= "otherwise,";
$output .= "&nbsp;";
$output .= $deleteurl;
$output .= "click here</a>.";

As you can see people can click on either 'send document' or 'click here'..

But instead of text links inside the actual paragraph,

I wanted to know if it's possible to create a 'Send' Button which leads to the same link but have this button below the paragraph, and 'Edit Info' which leads to the other link also below the paragraph.

Thanks guys,

Mike

darrenG

9:51 pm on Feb 12, 2008 (gmt 0)

10+ Year Member



When a form submit button is clicked, the button that was clicked is included in the request (via either post or get, depending on what method you specify in the form tag).

Therefore, when the script that is loaded from the forms action tag after a submit button is clicked, it should test for which button was clicked (which button ID is set in POST for e.g.), then either redirect to the appropriate page, or include a file or call a function based on the users click.

Hope that makes sense and helps your thought process..

phpguy54

3:00 pm on Feb 13, 2008 (gmt 0)

10+ Year Member



Thanks,

I'm not really a guru in php, so it only makes some sense. But can't I just create a button in photoshop, and then link that image to one of the url's above?

cameraman

6:17 pm on Feb 13, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, that's how I'd do it.
From what you've posted it doesn't appear to even need to be in a form.

phpguy54

6:22 pm on Feb 13, 2008 (gmt 0)

10+ Year Member



Hmm, but I thought it has to be in php since the script is in php? Basically this is a php cookie and I'm trying to create custom buttons that link to the variables within the code...not sure if that makes sense

cameraman

7:00 pm on Feb 13, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can intersperse php and html at your whim. For example:
.
.
$deleteurl = "<a href=\"index.php?q=file_download/refresh/" . $fileid . "\">";
?>
Thanks for your interest in XYZ<br><br>
If you are <?php echo "$fname $lname"; ?> please click on
<?php
for($i = 0; $i < 10; $i++) {
// do stuff
} // just an example, doesn't relate tor what you're doing right now.
?>
<a href="<?php echo $someurl; ?>"><img src="<?php echo $img_src; ?>"></a>

darrenG

9:32 pm on Feb 13, 2008 (gmt 0)

10+ Year Member



I appear to have made it more complex than needed, I must read posts more carefully.. sorry for any confusion..

cameraman

9:52 pm on Feb 13, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No worries ;)

One of the things that makes php so cool is that often you wind up with something simpler than you thought it would be going in (although the reverse is always a possibility LOL!)

phpguy54

2:05 pm on Mar 10, 2008 (gmt 0)

10+ Year Member



When i try to do this it breaks the code. Basically i need to either have one of those grey standard form buttons or an image button. But it needs to in this kind of format. The php echo breaks everything. Here's how the code works. I define the url like:

$deleteurl = "<a href=\"index.php?q=file_download/refresh/" . $fileid . "\">";

and then specify $deleteurl in the code i have after that.

But how would I do this with trying to put in "img_src"?

Here is what i'm trying to do. I want the "Edit Info" and "Send" links in the code below to be buttons of some sort...whether image or form buttons doesn't matter. So how would i make these buttons with the format i have?

$deleteurl = "<a href=\"index.php?q=file_download/refresh/" . $fileid . "\">";


$output = "Please click Send to receive requested item at $email <br><br>";
$output .= "To change your information please click Edit Info.<br><br>";
$output .= "&nbsp;";
$output .= $fileurl;
$output .= "send document</a>.";
$output .= "&nbsp;";
$output .= "otherwise,";
$output .= "&nbsp;";
$output .= $deleteurl;
$output .= "click here</a>.";
$output .= $img_src;
$output .= "click here</a>.";

Thanks

vfoo

2:25 pm on Mar 10, 2008 (gmt 0)

10+ Year Member



If I understand your request?:

Just as cameraman posted ( IMG tag within A tag)

$deleteurl = "<a href=\"index.php?q=file_download/refresh/" . $fileid . "\">";

$img_src= "<a href=\"some_other_url.php"\"><img src=\"your_image.gif\" border=\"0\">";

Of course you could also use an onclick on the img tag (I prefer to do this when making links that are not text myself).

It's a pretty good idea to separate your code from your presentation as cameraman also did for ya in his example. Quite often in your clients (or your) sites someone else may need to work on it. If you separate things nicely for them it won't be a horrible mess of code to try to review / fix. (When I come across that I usually trash old code completely because it's faster to write from scratch ;) )

phpguy54

12:34 am on Mar 11, 2008 (gmt 0)

10+ Year Member



Hey thanks for the reply..

But for some reason that code still breaks the page.

I saw that the </a> is missing. Where should this be?

Thanks