HTML form submits an empty string when JavaScript indicates the hidden control has a value -
amongst many other controls, have following html elements on form
<input id='cmdregisterme' name='cmdregisterme' value='register me' onclick="return presubmit();" type='submit' /> <input type="hidden" id="newhash" name="newhash" value=""> <input type="text" id="email" name="email" value="" size="50" maxlength="50"> <input type="password" id="password1" name="password1" value="" size="30" maxlength="25"> <input type="password" id="password2" name="password2" value="" size="30" maxlength="25">
and js functions
function presubmit() { document.getelementbyid("newhash").value = donewhash(document.getelementbyid("password1").value, document.getelementbyid("email").value.tolowercase()); alert(document.getelementbyid("newhash").value); document.getelementbyid("password1").value = ''; document.getelementbyid("password2").value = ''; return true; } function donewhash(pw, strusername) { var hash_padding = '************'; return sha1(sha1(pw) + hash_padding + strusername); }
when click submit, see expected hashed value displayed call of alert().
however, in php, value of $_post['newhash'] empty string. cannot fathom why happens. in understanding, there no other code executed after onclick() function returns true. have done global search on code 'newhash' , there no other assignments it.
if replace line
document.getelementbyid("password1").value = '';
with this
document.getelementbyid("password1").value = document.getelementbyid("newhash").value;
and inspect $_post['password1'], contains hash value. on earth happening wipe out value of 'newhash'?
i have found wrong, hope posting question may else. saved php-generated html file, added top, , resolved remove code piece piece , submit until submitted value newhash no longer empty. found had 2 hidden controls called newhash - js displaying value in one, , browser submitting other!
Comments
Post a Comment