Page 1 of 1

form within a form?

Posted: Wed Jul 13, 2011 8:48 am
by IGGt
Hi Guys,

I don't know if this is possible, but thought I would ask.

I currently have a page which has a form on it. The form is comprised of five 'groups' of buttons. When the Submit button is pressed the next page loads and the database is updated based on the selections made.

However, what I am trying to achieve is having a second submit button,so that when I press the second submit button, only the selection from the first 'group' is updated on the database, and the whole page then refreshes.

However, if I press the original Submit button, then the database is updated with the selections from all the groups, including the first group.

Any ideas?

Re: form within a form?

Posted: Wed Jul 13, 2011 9:21 am
by Weirdan
And what would happen if user submits form by pressing 'enter' on keyboard?

Re: form within a form?

Posted: Wed Jul 13, 2011 11:20 am
by IGGt
Good Point. I think I will just have to use two separate forms, and clearly mark them as such.

Re: form within a form?

Posted: Wed Jul 13, 2011 11:46 am
by AbraCadaver
IGGt wrote:Good Point. I think I will just have to use two separate forms, and clearly mark them as such.
Make a data array for all groups, then put each group into an of the data array, name="data[first][]", etc... Then have two submit buttons name="submit" value="button1", name="submit" value="button2".

Now on the receiving page, make a decision based on the button and act on either the overall data array or just the first array within the data array. This is just a rough example of an idea since I haven't seen your code:

Code: Select all

switch($_POST['submit']) {
   case "button1":
      $data = $_POST['data'];
      break;

   case "button2":
      $data['first'] = $_POST['data']['first'];
      break;
}
//loop and do stuff with data

Re: form within a form?

Posted: Fri Jul 15, 2011 6:09 am
by IGGt
An excellent idea there. I had to add an extra page so I could route to the relevant location (button1 > new page / button 2 > reloads current page), but apart form that it works like a treat.


cheers