将参数传递给HTML中的表单操作 [英] Pass parameter to form action in HTML

查看:59
本文介绍了将参数传递给HTML中的表单操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用此处的文件来实现简单的文件上传:

I am trying to implement a simple file upload using the files here :

http://www.sanwebe.com/2012/05/ajax-image-upload-and-resize-with-jquery-and-php

我让它工作并设法通过CSS更改样式等,并更改文件名等.

I have it working and managed to change the styles etc via CSS and change the filenames etc etc.

我现在需要在iframe中使用它,并为文件名传递一个变量.

I now need to use this in an iframe and pass a variable for the filename.

在我的应用中,我可以使用localstorage,setItem('clientID',10)或向iframe网址添加参数.www.xxx.com/uploads?clientID= 10.

In my app I can use either localstorage,setItem('clientID',10) or add a parameter to the iframe url. www.xxx.com/uploads?clientID= 10.

插件有一个html文件,然后使用以下命令调用php文件:

The plugin has an html file that then calls the php file with :

<form action="processupload.php" method="post" enctype="multipart/form-data" id="MyUploadForm">

那么将我的clientID变量保存到final.php文件的正确"方法是什么.

So what is the 'correct' method to get my clientID variable to the final.php file.

我可以在HTML文件中使用javascript并将变量传递给表单操作,即:

Can I use javascript in the HTML file and pass the variable to the form action ie:

<form action="processupload.php?"+clientID method="post" enctype="multipart/form-data" id="MyUploadForm">

或者我可以在html文件中获取url参数并将其添加到表单操作中.

Or can I grab the url parameter in the html file and add to the form action.

我在body标记后尝试了此操作:

I tried this after the body tag:

<?php
$clientID='100';
?>

然后将表单操作更改为:

Then changed the form action to :

<form action="processupload.php?clientID=" <?php echo $clientID ?> method="post" enctype="multipart/form-data" id="MyUploadForm">

然后在我添加的PHP文件中:

Then in the PHP file I added:

$clientID = $_GET["clientID"];

,并将文件名详细信息更改为:

and changed the filename details to:

$NewFileName        = $clientID.$File_Ext; //new file name

该过程在我上传文件时有效,但clientID为空.例如,文件名为".png"而不是"100.png"

The process works as I get the file uploaded but the clientID is blank. eg the file is name '.png' instead of '100.png'

MarWarby

推荐答案

如果要通过HTML ......

If you want to do it through HTML....

代替

<form action="processupload.php?clientID=" <?php echo $clientID ?> method="post" enctype="multipart/form-data" id="MyUploadForm">

尝试一下:

<form action="processupload.php?clientID=<?php echo $clientID ?>" method="post" enctype="multipart/form-data" id="MyUploadForm">

如果仍然无法正常工作(某些服务器不喜欢将POST和GET混合使用),请尝试交换以下内容:

If that still doesn't work (some servers don't like mixing POST and GET), then try swapping for this:

<form action="processupload.php" method="post" enctype="multipart/form-data" id="MyUploadForm">
    <input type="hidden" name="clientID" value="<?=$clientID;?>" />
    <!-- the rest of your form -->
</form>

然后在您的PHP文件中,将 $ _ GET 替换为 $ _ POST .

And then in your PHP file, swap the $_GET for $_POST.

这篇关于将参数传递给HTML中的表单操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆