Welcome Guest, Not a member yet? Register   Sign In
How can I populate the URI with form values
#1

[eluser]fantomex[/eluser]
Clunky title but: say I have a form
Code:
<?php
echo form_open('/index');
echo form_input('data');
echo form_submit();
?>

If someone types in "foo" and submits, the /index page then shows data based on the value of 'foo'. How can I get it to submit to /index/data/foo so that there's a canonical url for that data which people can then bookmark/send a link etc. The options seem to be to turn $_GET on and have /index/?data=foo or send to an intermediate page which reforwards to index/data/foo. Anything else?
#2

[eluser]mddd[/eluser]
You can use a little javascript that builds the right url to go to when the form is submitted. Something like:
Code:
<form action="" method="get" name="myform">
<input type="text" name="data" />
</form>

// [removed]
function build_action()
{
  var action = '/index/' + document.myform.data.value + '';
  document.myform.action = action;
}
#3

[eluser]fantomex[/eluser]
Oh yeah, something like that could work as well. This is only for an internal project where I know everyone will be using it through a full browser with js turned on. Cheers!




Theme © iAndrew 2016 - Forum software by © MyBB