blatcho Posted December 9, 2012 Share Posted December 9, 2012 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> Quote Link to comment https://forums.phpfreaks.com/topic/271788-building-urls-using-form-action/ Share on other sites More sharing options...
PFMaBiSmAd Posted December 9, 2012 Share Posted December 9, 2012 When using the GET method for a form, the only get parameters that are put into the URL are from the form fields. You would need to use hidden form fields to pass any existing get parameters. Quote Link to comment https://forums.phpfreaks.com/topic/271788-building-urls-using-form-action/#findComment-1398396 Share on other sites More sharing options...
blatcho Posted December 9, 2012 Author Share Posted December 9, 2012 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.. Quote Link to comment https://forums.phpfreaks.com/topic/271788-building-urls-using-form-action/#findComment-1398404 Share on other sites More sharing options...
blatcho Posted December 9, 2012 Author Share Posted December 9, 2012 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? Quote Link to comment https://forums.phpfreaks.com/topic/271788-building-urls-using-form-action/#findComment-1398412 Share on other sites More sharing options...
blatcho Posted December 9, 2012 Author Share Posted December 9, 2012 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> Quote Link to comment https://forums.phpfreaks.com/topic/271788-building-urls-using-form-action/#findComment-1398420 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.