views:

262

answers:

3

I am trying to create a page that lets a user delete an image if he is logged in. I pass the image ID through the URL when the button is clicked. The problem is it does catch the image ID but when I click delete it passes the value of the button to the URL instead of the image ID. It looks like user_acc_images.cfm?delete=Delete instead of user_acc_images.cfm?uploaded_image_id=1 in the browser.

Here's my code:

<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>
+2  A: 

Remove the ?uploaded_photo_id=#uploaded_photo_id# part of the URL string in the form, and add a hidden input like this:

<input type='hidden' name='uploaded_photo_id' value='#uploaded_photo_id#'>
Paolo Bergantino
+2  A: 

Paolo is right, but I would also add that the reason you are having this trouble is because when you do a form GET any url variables in the action url are not passed along. His solution is best but you could also change it to a form post and then the url variables you are passing through the action attribute will be passed through.

Ryan Guill
+2  A: 

change method="get" to method="post"

Henry