tags:

views:

750

answers:

3

Hi,

I have a form, text input and a submit button. How do I append the value of the text box to the form action i.e.

action="https://www.mywebsite.com/" & txtSessionId

The form looks like this:

<form name="form1" method="post" action="https://www.mywebsite.com/"&gt;
  <label>Your Sessions ID:
    <input type="text" name="txtSessionId" id="txtSessionId">
  </label>
  <label>
<input type="submit" name="btnContinue" id="btnContinue" value="Continue">
</label>
</form>

I want the link to look like this: https://www.mywebsite.com/123456

where 123456 is typed into the text box by the user.

Thank you

+2  A: 

You'd have to either use javascript or something server-side to do that (or both).

Javascript:

<form name="form1" method="post" action="https://www.mywebsite.com/" 
  onsubmit="location.href = this.action + this.txtSessionId.value; return false;">

Server-side (PHP)

if (!empty($_POST['txtSessionId']))
{
    header('Location: https://.....' . (int)$_POST['txtSessionId']);
    exit();
}
Greg
thank you, I used the javascript method (within a drupal block) and it worked perfectly.
Belliez
A: 

I assume you are using something like mod-rewrite on your server if you are accepting URLs like this. So, why not just write a rule on there to check if txtSessionId is set and then re-write it to whatever you'd like?

I don't know how to write mod-rewrite rules all that well, but, I definitely know you can do it.

If you're using PHP, Greg did present a fairly viable alternative to using mod-rewrite (or something similar).

KyleFarris
+1  A: 

The correct behavior is to send the input field to the existing form, process it, and redirect. You don't know if the user sent a valid input value yet!

In this cases I always recommend javascript unless accessibility is an strict requirement for you.

rgz