form within a form?

HTML, CSS and anything else that deals with client side capabilities.

Moderator: General Moderators

Post Reply
IGGt
Forum Contributor
Posts: 173
Joined: Thu Nov 26, 2009 9:22 am

form within a form?

Post 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?
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: form within a form?

Post by Weirdan »

And what would happen if user submits form by pressing 'enter' on keyboard?
IGGt
Forum Contributor
Posts: 173
Joined: Thu Nov 26, 2009 9:22 am

Re: form within a form?

Post by IGGt »

Good Point. I think I will just have to use two separate forms, and clearly mark them as such.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: form within a form?

Post 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
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
IGGt
Forum Contributor
Posts: 173
Joined: Thu Nov 26, 2009 9:22 am

Re: form within a form?

Post 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
Post Reply