I can't quite tell if you fully understand the relationship between Javascript and PHP, so I'm going to assume that you don't. PHP runs on the server and outputs HTML to the browser (along with some headers and other stuff). Once the HTML is sent to the browser, what the user does with your site is out of your control until his browser performs another GET or POST request (or opens a persistent web socket connection). As you mentioned, it's impossible for PHP to outright read the value of the hash, as it's meant to be confined to the browser, accessible only via Javascript. Since your PHP script for that particular request has stopped running and the page data has already been output to the browser, what sense does it make to grab the value using Javascript, send it back to PHP with another http request, use the set_value() function, and then what?
If you use window.location.hash and set the value of your input box equal to it, you will be able to use set_value() when the user submits the form. Take a look at CI's set_value() helper function:
function set_value($field = '', $default = '')
{
if (FALSE === ($OBJ =& _get_validation_object()))
{
if ( ! isset($_POST[$field]))
{
return $default;
}
return form_prep($_POST[$field], $field);
}
return form_prep($OBJ->set_value($field, $default), $field);
}
It first checks to see if you've set up form validation object. If you have, it runs the form_prep() function using that object's set_value (presumably to manage any rules you've set up in your form validation. If you haven't, it sees if that field exists in the $_POST array. If it doesn't, it returns the default value. If it does, it returns the value from the $_POST array. So if you a) set up a form validation rule for it and b) give that input box the name you want to use in your set_value() function, you will be able to retrieve the value of the hash in PHP which you have entered into that input box using Javascript.