开发者

How to fetch a text input's data and pass it to an url as parameter in html?

I have this code

<form enctype="multipart/form-data"  method="post" action="?" name="test">
  <input name="number" size="20"  maxlength="30" type="text">
  <br>
  <input value="Reset" type="reset">
  <input  name="Submit" value="Go" type="submit">
</form>

Problem is the ?. What I want to do is fetch the number and load a new page with http://url.com/"number".html

开发者_JAVA技巧

What should ? look like to make this happen?


<form enctype="multipart/form-data"  method="post" onsubmit="this.action=document.getElementById('numberInput').value+'.html';" action="" name="test">
  <input name="number" id="numberInput" size="20"  maxlength="30" type="text" />
  <input value="Reset" type="reset" />
  <input  name="Submit" value="Go" type="submit" />
</form>

This is what the code should look like to get this functionality. I think I do not have to mention that this is very unsafe :-) If you determine the target of your post at client side, the client can sent this form to every site he wants! To avoid this you would have to validate it's input at server side...

You could send the form to one php file at the server, determine the target and upload the file to this new target with curl, for example.


You don't have to do anything. This is the browser's task. You should only set your form's method to GET and provide the link for your script on the server which is going to handle the information of this form. That's all.


 //one.php
 <?php
 $num=$_REQUEST['number'];
 header("Location:two.php?number=".$num);
 ?>

 <form enctype="multipart/form-data"  method="post" action="one.php" name="test">
 <input name="number" size="20"  maxlength="30" type="text">
  <br>
 <input value="Reset" type="reset">
 <input  name="Submit" value="Go" type="submit">
 </form>


The ? is the page where the data you input in the form is submitted to. Let's say you call it handleSubmit.php

<form enctype="multipart/form-data"  method="post" action="handleSubmit.php" name="test">
  <input name="number" size="20"  maxlength="30" type="text">
  <br>
  <input value="Reset" type="reset">
  <input  name="Submit" value="Go" type="submit">
</form>

Then you must create a file named handleSubmit.php and insert this data to handle the data passed from the form:

<?php
//get data from the post
$number = $_POST['number'];
//redirect to that page
header('Location: '.$number.'.html');


You can't use a standard HTML form action for that. You will need to add some JavaScript to the form's onSubmit even, read the value of the number input, and redirect the page accordingly.

EDIT: What strauberry said...


get the value as one of the request parameter and write that number in scriptlet

Ex:- <% String number = request.getParameter("number"); %>

" name="test">

Or

write the value to a javascript valiable [usually will be a text until you do eval] and assign that value to the form using a function. Call this function onSubmit of the form or on click of a button

Ex:-

function send(form, action) { var fullpath = ""; form.action = fullpath; form.submit(); }

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜