Jump to content

Recommended Posts

Hi all,

 

OK so I'm sure this is really simple, but I can't see the issue with my code; all I'm trying to do is build a URL from a form text action. Simply echo'ing the $URL variable back produces the correct URL, however when trying to include the variable in the form action, it does not include the $PatNumber

 

As way of background, I'm an Intellectual Property analyst looking to make my life easier on patent\trademark searches; the EPO has an online REST service (which I'm also learning about) for searching Patents, so I'm trying to build a form where I can enter a patent number and retrieve the back bibliographic data.

 

<?php

$PatNumber = $_GET['EPOPN'];

$URL = "http://ops.epo.org/2...tNumber}/Biblio";

echo $URL;

?>

 

<html>

<body>

<form action="<?php echo $URL?>" method="GET">

Patent Number (EPO Format) <input type="text" name="EPOPN" />

<input type="submit" />

</form>

</body>

</html>

Link to comment
https://forums.phpfreaks.com/topic/271788-building-urls-using-form-action/
Share on other sites

I see; so, is this the wrong approach entirely to defining variables in a URL string? I'm reading up on the GET method, plus a number of other areas which look relevant (http_build_query look's to be good?), could you advise the best approach? The problem I have with the form GET method is most of the examples I've seen simply append the exiting URL with the form variable entries, as opposed to an entirey different URL, which this is..

So, i've taken it back further to basics; I have a variable for each part of the URL needing 'building', I simpyl need to replace the $patNumber variable with the form input (and eventually the $modifier, but for now one variable is fine!):

 

<?php

$baseURL = "http://ops.epo.org/2.6.2/rest-services/published-data/publication/epodoc/";

$patNumber = "EP1000000";

$modifier = "/Biblio";

$epoq = $baseURL.$patNumber.$modifier;

echo $epoq;

?>

<html>

<body>

<form action="<?php echo $epoq ?>" method="GET">

Patent Number (EPO Format) <input type="text" name="patNumber" />

<input type="submit" />

</form>

</body>

</html>

 

I see the form text input only appends the variables entered to the end of the URL defined; so this does not seem like the right way to build the url. Should I be looking at building a query instead, then passing that back? This still gives the issue of how to take a FORM input and utilise it within the URL string?

After a bit of playing around, and using POST instead of GET, I got it working. It's not pretty, but it works..

 

 

<?php if($_SERVER['REQUEST_METHOD'] == 'POST') :

$epoNumber = $_POST['epopn'];

header('Location: http://ops.epo.org/2.6.2/rest-services/published-data/publication/epodoc/' . $epoNumber);

else:

?>

<head>

<title>EPO Patent Search</title>

</head>

 

<body>

 

<form action="<?php echo $_SERVER['../PHP_SELF']; ?>" method="post">

Patent Number (EPO Format) <input type="text" name="epopn" />

<input type="submit" value="Go" />

</form>

<?php endif; ?>

</body>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.