ColdFusion URL属性返回按钮名称而不是必填字段(ID)

时间:2009-03-28 00:10:49

标签: mysql coldfusion

我正在尝试创建一个页面,让用户在登录后删除图像。 单击按钮时,我会通过URL传递图像ID。 问题是它确实捕获了图像ID但是当我单击删除时它将按钮的值传递给URL而不是图像ID。 在浏览器中看起来像user_acc_images.cfm?delete=Delete而不是user_acc_images.cfm?uploaded_image_id=1

这是我的代码:

<cfif isdefined("session.username")>
<cfoutput><h3 class="uname">Hello #session.username# </h3></cfoutput></cfif>

<h2>Your Uploaded Images</h2> 
<p>On this page you can view the list of all the images you uploaded.You can also delete some of your photographs if you wish.</p>  
    <table cellspacing="25">     
    <cfif isDefined("session.username")>
    <cfinvoke component="cfc.user_acc_images" method="viewimages" returnvariable="vimages">
        <cfoutput query="vimages">
           <tr>
           <cfform name="formurl" action="http://www.humbermedia3.ca/portfolio0809/farnauz/AcePhotographyMain/user_acc_images.cfm?uploaded_photo_id=#uploaded_photo_id#" method="get"> 
            <td align="left">
                <img src="#uploaded_photo_name#" name="photo_name" width="200" height="200"/>
                </td></tr><tr><td>
                <b>Uploaded on: </b>#upload_date# <br/><br/>
                <!---<button type="submit" name="delete" value="Delete" class="button" >--->
                <input type="submit" name="delete" value="Delete" class="button" />
                <br/><br /><hr/>
            </td> 
            </tr></cfform>
          </cfoutput> 
    </table>

<cfelse>
    <cfoutput> 
         <h3>Sorry you cannot access this page.<h3>
            <p>
                You have to be logged in to view your uploaded images.<br/><br/>
                Click<a href="login.cfm"> here </a>to log in.<br/>
                Dont have an account? Click<a href="register.cfm"> here </a>to create a new account.
            </p>
    </cfoutput>
</cfif>

<cfif isDefined("form.delete")>
    <cfinvoke component="cfc.user_acc_images" method="deleteimage" returnvariable="dimage">
    <cfinvokeargument name="url" value="#URL.uploaded_photo_id#">
    <cfoutput>#URL.uploaded_photo_id#</cfoutput>
</cfif>

3 个答案:

答案 0 :(得分:2)

删除表单中URL字符串的?uploaded_photo_id=#uploaded_photo_id#部分,并添加如下隐藏的输入:

<input type='hidden' name='uploaded_photo_id' value='#uploaded_photo_id#'>

答案 1 :(得分:2)

保罗是对的,但我还要补充一点,你遇到这个麻烦的原因是因为当你做一个表格时,动作网址中的任何网址变量都不会被传递。他的解决方案是最好的,但您也可以将其更改为表单帖子,然后通过操作属性传递的url变量将通过。

答案 2 :(得分:2)

将method =“get”改为method =“post”