• Welcome to Overclockers Forums! Join us to reply in threads, receive reduced ads, and to customize your site experience!

Submitting to a php form handler with only a simple hyperlink

Overclockers is supported by our readers. When you click a link to make a purchase, we may earn a commission. Learn More.

macklin01

Computational Oncologist / Biomathematician / Mode
Joined
Apr 3, 2002
Location
Bloomington, IN
Hi, everybody.

I'm trying to do some last cleaning up on the following php page I wrote:

http://www.math.uci.edu/~pmacklin/Publications.php

This URL parses an XML file of publications:

http://www.math.uci.edu/~pmacklin/Publications.xml

It inserts DOI (digital object identifier), BibTeX (bibliography for LaTeX), PDF, and abstract links when the information is defined for a publication entry.

My problem is on the abstract portion. Right now, I just have links of the form
Code:
<a href="php_functions/abstract.php?Abstract=<string>&Title=<string>">[Abstract]</a>

That passes the abstract and title information over to a very simple abstract.php page, which pastes the appropriate text in the appropriate places. (Just try clicking one.) It uses
Code:
$abstract = $_GET['Abstract'];
$title = $_GET['Title'];
to get the info from the URL for the page.

Okay, so there's the background information. Now, for the question:

Is there any way to get rid of all the mess in the URL, perhaps by using a hidden form? I'd still like it to appear as a simple HTML text link on the Publications.php page. Please excuse my noobiness on PHP--I'm fairly amateur at PHP. I'm still tickled pink just to have written a simple and robust XML parser with objects for PublicationItems, etc.

Thanks in advance for any recommendations!! -- Paul
 
Bump! It looks like your site is still using the uber-long urls, so I figured I'd help you out (even a month later :p)

The first thing you want to do is move all of your abstracts and titles into the abstract.php file. This way no one sees it. Do it like so:
Code:
<?php
$abstracts[0]["title"]="First title";
$abstracts[0]["abstract"]="First abstract";
?>
Instead of "title" and "abstract" you could just use 0 and 1 so you dont have to rewrite it every time.

Then instead of passing the whole abstract and the whole title, you just pass some id assigned to each abstract (First is 0, second is 1, etc). Your url looks like

php_functions/abstract.php?id=0

and you just use $id = $_GET['id']
and $abstracts[$id]["title"]

Since you're pulling the abstracts from the xml, you'll have to copy your xml parser into the abstract.php file to pull the data.

If you don't want to mess with the abstract.php file, you could always use hidden form inputs. You could use some javascript to have one input and change it depending on the link clicked, or you could have several forms.

The form would look like:
Code:
<form method="post" name="form0" action="abstract.php">
<input type="hidden" name="abstract" value="[ABSTRACT]">
<input type="hidden" name="title" value="[TITLE]">
</form>

<a href="javascript:document.form0.submit()">Abstract</a>
Where I have form0, you could probably just use a for loop and increase the number by one for each abstract, since you have a different form for each abstract, and the names have to be different so the link submits its respective form.

With that your $_GET["title"] will still work the same way, you just won't see anything in the url.

Feel free to PM me if you have more questions.
 
kayson said:
Bump! It looks like your site is still using the uber-long urls, so I figured I'd help you out (even a month later :p)

The first thing you want to do is move all of your abstracts and titles into the abstract.php file. This way no one sees it. Do it like so:
Code:
<?php
$abstracts[0]["title"]="First title";
$abstracts[0]["abstract"]="First abstract";
?>
Instead of "title" and "abstract" you could just use 0 and 1 so you dont have to rewrite it every time.

Then instead of passing the whole abstract and the whole title, you just pass some id assigned to each abstract (First is 0, second is 1, etc). Your url looks like

php_functions/abstract.php?id=0

and you just use $id = $_GET['id']
and $abstracts[$id]["title"]

Since you're pulling the abstracts from the xml, you'll have to copy your xml parser into the abstract.php file to pull the data.

If you don't want to mess with the abstract.php file, you could always use hidden form inputs. You could use some javascript to have one input and change it depending on the link clicked, or you could have several forms.

The form would look like:
Code:
<form method="post" name="form0" action="abstract.php">
<input type="hidden" name="abstract" value="[ABSTRACT]">
<input type="hidden" name="title" value="[TITLE]">
</form>

<a href="javascript:document.form0.submit()">Abstract</a>
Where I have form0, you could probably just use a for loop and increase the number by one for each abstract, since you have a different form for each abstract, and the names have to be different so the link submits its respective form.

With that your $_GET["title"] will still work the same way, you just won't see anything in the url.

Feel free to PM me if you have more questions.

Ah, thanks for the post. I'll have to give that a look over the weekend or next week. Those look like some great tips!! :)

The other solutions that were posted were good, but I didn't really want to mess with extra packages, etc. (And since I'm only a user on some server, it wasn't even clear if I'd be able to add new packages.)

I think I'll probably leave the .xml files as is. (I don't care that people can see those from the outside, and I don't want to maintain multiple copies of that information. In fact, I view that as the point of separating the php data handlers from the xml data.) So, the hidden form option is probably preferred. :)

Have a great holiday!! -- Paul
 
Back