0

I'm going to ask probably the stupidest question you've ever heard (shame on me). I want to make write a markup for table which should look something like this:

============================================================
| Layout  | Date edited | Actions | Is active | Is default |
============================================================
| lauout1 | 04.05.2012  |[Delete] |    [ ]    |     o      |
...

Fourth and fifth columns contain check box and radio button correspondingly and third got button. Button submission should be proceed by one page on site and check box with radio - by other one. But according to this question I can't place one element inside another one! I mean one global around whole table and one around each delete button. I think I'm going to do something really awful.. What is the right solution?

Community
  • 1
  • 1
east825
  • 909
  • 1
  • 8
  • 20
  • Use two different forms at each depth element? I guess I'm not seeing what the problem is here. What server side technology are you using? Can you use Ajax? Etc – Tejs Jun 12 '12 at 18:14
  • I'm using Django and yes I thought about JavaScript, but I actually a newbie with it and will appreciate if you suggest some script for my problem. P.S. no Ajax.. yet... I hope there is some simpler solution – east825 Jun 12 '12 at 19:11

1 Answers1

0

You still can use one form element with the whole table inside it, and put as many submit buttons as deletes you want. The name of each button will be sent to your script with the value on it. For example:

<form method="post">
    <!-- table ... -->
    <!-- first item ... -->
    <input type="submit" value="Delete" name="delete1" />

    <!-- second item ... -->
    <input type="submit" value="Delete" name="delete2" />

    <!-- ... -->
</form>

Clicking different buttons will post only the button you pressed, you can parse the id to see what button you pressed.

On the following php script, if you press the first delete button we saw before, you get something like:

<?php
    isset($_POST["delete1"]); //true
    isset($_POST["delete2"]); //false
?>

For checkboxes and option items use input arrays:

<input type="checkbox" name="check[]" value="firstitemid" />
<input type="checkbox" name="check[]" value="seconditemid" />

On your php code you will receive an array on $_POST['check']

I want to recommend you also read about Cross-site request forgery

Firula
  • 1,251
  • 10
  • 29
  • I used hidden fields with unique ids in each inner form with 'Delete' button - think it more clear But what about the other form for the radio group and check boxes? – east825 Jun 12 '12 at 18:39
  • You can use input arrays: – Firula Jun 12 '12 at 18:46
  • Actually your solution is to use single form - but I want to avoid this and make different functions responsible for deletion my objects and doing all other. And I don't use PHP - I'm with Django) – east825 Jun 12 '12 at 19:07
  • You still will receive an array in Django. My answer just fits for the question about how to avoid nesting forms. You always can use ajax instead! Good luck! – Firula Jun 12 '12 at 19:12
  • Thanks, but I still don't understand why use arrays here (and what it means here actually too). If all check boxes have the same name (e.g. check) but different values selected ones will be sent as check=1&check=3&check=94 and I can get this list on server side without any special naming. Is is some PHP-specific-magic? – east825 Jun 12 '12 at 19:28
  • No magic, the fact is, if the checkbox is not checked, the value for that check will not be send to server. I edited reply to be clear. – Firula Jun 12 '12 at 19:45