3

I have a form which when submitted goes to the url "signup.php?username=xx" where xx is an input field. Instead of this I was wondering if I could get it to go to the following url "signup/xx" where xx is taken from the input field.

John Doe
  • 836
  • 2
  • 10
  • 17

3 Answers3

3

You need to use Javascript and some type of .htaccess for that. But why don't you use POST instead of GET?

I don't want singup?username=sawny&password=1234 in my history.

EDIT:

I had done something like this:

$(document).ready(function() {
    $("submit[name='foo']").live('submit', function() {

        var usr = $("form input[name='user']").val();
        $("form input[name='user']").remove(); //Else it will be singup/usr?user=

        $("form[name='bar']").attr("action", "singup/"+ usr);
    });
});

and then the regexp @zero posted in a .htaccess file.

Sawny
  • 1,404
  • 2
  • 14
  • 31
  • I'm only passing the username through therefore I don't mind about the history, I just wanted it to look neater because right now the url it submits to is signup.php?username=xx but I have a rewrite rule for signup/xxx to signup.php?username=xx. Therefore if I can get the form to submit to signup/xx the ht.access will take care of the rest. I hope I make sense – John Doe Nov 04 '11 at 16:56
0

Include jQuery if not already included

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>

and then add this script

<script>
$(function(){
    $("form").submit(function(e){
        e.preventDefault();
        var action = $(this).attr("action");
        var username = $(":input[name='username']").val();
        action = action + "/" + username;
        location.href = action;
    })
})
</script>
amit_g
  • 30,880
  • 8
  • 61
  • 118
-1

Try this:

RewriteRule ^signup/([^/]*)$ /signup.php?username=$1 [L]
ZeroSuf3r
  • 1,961
  • 8
  • 25
  • 36