Jump to content

Action attribute problem in form to delete user data


codeboyuk

Recommended Posts

Hi

 

I am building a class to manage site users (Via a CMS).

 

In order to complete this I am building a delete/remove user function/method. Things are going ok (I think), but I am confused about what to put in the action tag of the form being used to process the data.

 

Before coding my method, I referred to a script that someone showed me which does something similar in functionality: it deletes photos previously uploaded to a folder, and also removes the associated information from the database.

 

I used this script as the framework for the code that I am working with.

 

Eveything seems to be working fine - EXCEPT - when I click on the 'delete users' button, nothing happens.

 

The first thing that I examined for error was the action attribute within my form.

The value of the action attribute is:

action = "<? php htmlentities($_SERVER["PHP_SELF"]) ?>"

 

This format has worked for previous forms.

 

I compared this to the action attribute within the script that I was using as a guide. It's value is set as follows:

 

action = "remove_photo.php?<?php echo "action='godel' ";?>

 

In this instance, remove_photo.php is the file that is being used to both process and display the form.

 

The reference script works perfectly but it uses a procedural approach .

 

For my application, I am using a more object oriented approach, so both my opening and closing form tag elements are stored in a seperate file to the class file that processes it. I am new to OO but relatively comfortable with the paradigm so far (my other methods etc are working fine).

 

I therefore suspect that the reason for my script's inability to process is due to the action attribute setting (I cannot be 100% sure of course!).

 

I am going to therefore apply the action attribute settings used successfully in the reference script, to the application that I am building.

 

However, the trouble is, I don't understand it :(

 

I don't like it when something works, but I can't see the logic behind why it does. I am not concerned about the form id or method attrbutes. I understand what is going on there - and why they are set as they are.

However, the action attribute is very difficult to understand for the following reasons:

 

1/ There is no variable/method/entity/object/ANYTHING called 'godel' elsewhere in the reference script.

For this reason I thought that it might not be needed, so removed the bit of code within PHP tags concerning it:

<?php echo "action='godel' ";?>

 

- When I did this - the script didn't work. In fact - nothing at all would process. This was a similar result to what was happening with the script I am building.

 

2/ I then put the PHP line back in, but replaced 'godel' with 'something'. I saved and processed the form.

- it worked.

 

3/ I then tried it again replacing 'godel' with an empty string i.e: ' '.

- it worked.

 

Has anyone come across forms being processed in a similar way before? If so, please could you explain what is happening here. I can't find anything relating to this type of occurence online....

 

I am going to place the php tags in the file I am building, to see if it has the desired effect. If it does, I will obviously keep it. But not understanding what is happening, or why it is happening is very annoying!!

 

Thanks

 

Will

p.s. I've just noticed that there are threads on here dealing with deleting data from a database etc. I'll have a read!

Link to comment
Share on other sites

It's hard to say without looking at the actual code, but I think the key portion of this code:

 

action = "remove_photo.php?<?php echo "action='godel' ";?>

 

is not the 'godel' part, but the fact that you are setting an "action" variable in the URL. Perhaps the script is checking for the existence of that variable (probably using $_GET['action']?) before processing the form? Again, hard to say without looking at the script as a whole.

Link to comment
Share on other sites

Based on working through your other question in a different topic, it looks like my guess about this issue was correct. The fact that 'godel' is used doesn't actually matter. What matters is that an $action variable is set in the URL is set when the form is submitted, thus allowing your isset($_REQUEST['action']) to return true, and your form to be processed correctly.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...