Post edit:
As I am unable to comment, I was unable to ask for clarification. You said:
Ammadu: after pressing activity2 buttons the page get (needs to be) redirected to another page (activiy2.php). At activity2.php i want to catch checkbox_test[] value with $_POST.
In that case, AFAIK, you can not explicitly redirect the request to activity2.php as form nesting is not allowed and "Activity2" submit buttons will always POST to activity1.php. The simplest thing you can do is check which submit button POST-ed the request and react acorrdingly (code for checking the POST variable is shown below in the pre-edit section).
Pre-edit:
Your questions seems a little bit unclear to me, but I'll try to answer it based on what you wrote at the end of the question:
Think about a table / form where you can select any line for delete (activity1), and buttons for the end of each line to edit the table row where the button has pressed (activity2).
Also, I am no professional, merely a student, and an amateur programmer.
I had a similar problem while attending web programming course at my college. Specifically, there were table rows with checkboxes at the end of the each row for deleting the rows and the "Edit" button next to each of them. There was a "Delete" button below the table that was used to call the script that would remove the rows that were marked for deletion. We were using some dirty, dirty hacks to make that work.
You asked about form nesting, quick Googling revealed that form nesting is not a valid code.
Unless you really need to do your tasks in a separate PHP script I would suggest checking the POST variable to see which button was used to POST the form data to the server:
<?php
if (isset($_POST['activity1'])) {
//code for activity1 button
}
elseif (isset($_POST['activity2'])) {
//code for activity2 buttons
}
?>
This approach is also causing another problem - there is no easy way to identify which row that button belongs to. What you can do is dynamically name the buttons in the process of creation for each row (activity2_1, activity2_2...) and then create a loop in the PHP script that would check which button was clicked, which is a very ineffective way of doing things. That was the dirty hack I used back when studying WP course.
What I would go for are simple anchors. You can create them inside a PHP loop like this:
<?php
//...rest of the code in the loop...
echo '<a href="/activity2.php?rowID=' . $current_row_id . '">Edit</a>';
//...rest of the code in the loop...
?>
The script activity2.php should then perform a simple GET check and do the rest of the job:
<?php
if (isset($_GET['rowID'])) {
//activity code
}
?>
If you really need to use the buttons:
- You can style the anchors using CSS to look like and behave like buttons and then use the code shown above;
...or, if you are allowed, you can use simple JavaScript code that you can generate inside the PHP loop in the same manner, like this (out of my head) and then echo it:
<?php
//...rest of the code in the loop...
echo '<input type="button" onclick="location.href="/activity2.php?rowID=' . $your_row_id . '";" value="Edit" >';
//...rest of the code in the loop...
?>
Hope this helps.