Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

2 submit buttons on 1 form

Explorer ,
Jun 21, 2006 Jun 21, 2006
I'm working from the excellent "PHP web development with Dreamweaver MX 2004" book but am struggling to adapt part of the case study.
The book says that it is possible to list the current members of a fictitious club in the order of their membership category. ie. most important position first!
It suggests adding a field to the category table which will contain a number relating to its importance. (I've used a varchar type! named "display_order")
The book then reminds the reader to amend the admin pages to reflect the changes.
The admin page currently contains 2 forms. The 1st form adds new categories. The 2nd form displays all of the categories (sorted according to display_order) with a radio button to select categories to delete.
To this form I have added the display_order which needs to be editable so I can alter the display_order. (I've included a hiddenfield of the category_ID on the table row before the "repeat region"! Is this right?)
Is it possible to have 2 sumit buttons on 1 form? 1 button to delete records and 1 to update records!

Thanks for your help!
TOPICS
Server side applications
397
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 21, 2006 Jun 21, 2006
maffew wrote:
> I'm working from the excellent "PHP web development with Dreamweaver MX 2004"
> book

Glad you like it. That case study was originally meant to be about 40
pages, but like Topsy, it just growed and growed. :)

> It suggests adding a field to the category table which will contain a number
> relating to its importance. (I've used a varchar type! named "display_order")

VARCHAR is a bad choice for that type of column because it's for text.
Consequently, item 11 will come before item 2! Use INT or TINYINT instead.

> To this form I have added the display_order which needs to be editable so I
> can alter the display_order. (I've included a hiddenfield of the category_ID on
> the table row before the "repeat region"! Is this right?)

It's a long time since I worked on it, but what I had in mind was
something I have created on a separate website. I have a different page
for setting the display order. All the items are displayed in a repeat
region with a text input field alongside them for the display order
number. The name of the text input field has square brackets after it,
so it creates an array display_order[]. Inside the repeat region, I
created another array made up of the category IDs. Then at the bottom of
the page, I used this:

<input name="cat_id" type="hidden" value="<?php echo implode(',',
$cat_id); ?>" />

When you submit the form, you then use explode() to turn cat_id back
into an array. This leaves you with two arrays: display_order and
cat_id. You can then use a loop like this:

for ($i = 0; $i < count($cat_id); $i++) {
$sql = 'UPDATE table SET display_order =
'.$_POST['display_order'][$i].' WHERE cat_id = '.$cat_id[$i];
mysql_query($sql);
}

> Is it possible to have 2 sumit buttons on 1 form? 1 button to delete records
> and 1 to update records!

Yes. Give the submit buttons different names. Then use this to
distinguish between them:

if (array_key_exists('delete', $_POST)) {
// delete code goes here
}
elseif (array_key_exists('update', $_POST)) {
// update code goes here
}

--
David Powers
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "Foundation PHP 5 for Flash" (friends of ED)
http://foundationphp.com/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 22, 2006 Jun 22, 2006
Thanks for your help David! It sounds complicated but I'll have a go!

I have another question!

My addmember.php and editmember.php have the dynamic menus populated by the categories table. However, when the members details are displayed, instead of the cat_type being displayed it shows the cat_ID. (in other words, it displays a "3" instead of "treasurer").

Any ideas as to what I'm doing wrong?

Many thanks!
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 22, 2006 Jun 22, 2006
maffew wrote:
> My addmember.php and editmember.php have the dynamic menus populated by the
> categories table. However, when the members details are displayed, instead of
> the cat_type being displayed it shows the cat_ID. (in other words, it displays
> a "3" instead of "treasurer").
>
> Any ideas as to what I'm doing wrong?

Yes, you're binding cat_ID to the page instead of cat_type.

--
David Powers
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "Foundation PHP 5 for Flash" (friends of ED)
http://foundationphp.com/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 22, 2006 Jun 22, 2006
I'm using a recordset that retrieves all columns from the "members" table and binding "category" to the page. Any other ideas?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 22, 2006 Jun 22, 2006
LATEST
maffew wrote:
> I'm using a recordset that retrieves all columns from the "members" table and binding "category" to the page. Any other ideas?

Look at Figure 9-3 on page 345. members.category is linked to
category.cat_id. You need a recordset that joins the two tables.

SELECT members.mem_ID, members.firstname, members.familyname
category.category
FROM members, category
WHERE members.category = category.cat_ID

With hindsight, it would have been better to use cat_ID instead of
category in the members table, as that would have made things clearer.

--
David Powers
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "Foundation PHP 5 for Flash" (friends of ED)
http://foundationphp.com/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines