phpBB2Refugees.com Logo
Not affiliated with or endorsed by the phpBB Group

Register •  Login 

Continue the legacy...

Welcome to all phpBB2 Refugees!Wave Smilie

This site is intended to continue support for the legacy 2.x line of the phpBB2 bulletin board package. If you are a fan of phpBB2, please, by all means register, post, and help us out by offering your suggestions. We are primarily a community and support network. Our secondary goal is to provide a phpBB2 MOD Author and Styles area.

form with multiple submit buttons?


 
Search this topic... | Search MOD Writing... | Search Box
Register or Login to Post    Index » MOD Writing  Previous TopicPrint TopicNext Topic
Author Message
guyb
Board Member



Joined: 30 Sep 2009

Posts: 11



PostPosted: Tue Oct 06, 2009 3:49 am 
Post subject: form with multiple submit buttons?

My question is a *tiny* bit more complex than that:

a) I'm working on designing an ACP form page which displays arrays of data (in rows; each row is an array)

b) at the end of each row is a "submit" button which is supposed to trigger a "mode" which enables an UPDATE of an sql table for that specific line item

My problem is, to identify that specific line item a certain variable has to be passed, but I can't have it referenced in my <form action= line because it will hardcode a certain number.

At the moment my form action references the .php page where the mode is located, but I don't know how to get the line item number passed when I press "submit" next to the relevant line... any suggestions?

Here's what I've got:

from the form page:
Code:
<form enctype="multipart/form-data" method="post" action="{S_ADMIN_OFFER_EDIT}">
// where S_ADMIN_OFFER_EDIT references: append_sid("admin_auction_offer.$phpEx") on that same .php page

// MY SUBMIT SECTION:
// This passes the unique line number
<td class="row2"><input type="hidden" name="offer_id" value="{offer.AUCTION_OFFER_ID}" />
// This references the "update" mode, to UPDATE sql table
<input type="hidden" name="mode" value="admin_offer_edit" />
// The submit button (whose name is that L_ variable
<input type="submit" name="submit" value="{L_ADMIN_AUCTION_OFFER_FIELD_EDIT}" /></td>
// The submit presently yields the URL admin_auction_offer.php+SID but not the mode or the object number - and it seems neither gets received on the .php page with the mode



I've been searching for possible solutions and one that came up was to:
a) add the "mode" value to the form action URL (because it's always the same mode if the submit button is pressed), and
b) on the "submit" button, to submit the item number there (so name="offer_id" and value="{offer.AUCTION_OFFER_ID}")

...would this be possible, and does it matter if the resulting URL places the "mode" name before the "offer_id" number? (does it matter what order those values are passed?)
Back to top
Ptirhiik
Board Member



Joined: 19 Nov 2008

Posts: 114


flag
PostPosted: Tue Oct 06, 2009 11:08 am 
Post subject: Re: form with multiple submit buttons?

You know the number of lines you display, so you know the number of buttons that can be pressed.

So name your button including the line number as extension: "submit_1" ie, then, assuming $count_line is equal to the number of lines displayed (_x & _y tests are required for image buttons):

Code:
$selected_row = false;
for ( $i = 1; $i <= $count_line; $i++ )
{
   if ( isset($HTTP_POST_VARS['submit_' . $i]) || (isset($HTTP_POST_VARS['submit_' . $i . '_x']) && isset($HTTP_POST_VARS['submit_' . $i . '_y'])) )
   {
      $selected_row = $i;
      break;
   }
}
if ( $selected_row !== false )
{
   // get the id linked to the row found: it can be stored as a hidden field following the same scheme, so ie $HTTP_POST_VARS['id_' . $selected_row]
}



Btw, the same method can be used to get checkboxes or multi-selection drop down list (eg not a single $selected_row, but an array of).
Back to top
guyb
Board Member



Joined: 30 Sep 2009

Posts: 11



PostPosted: Wed Oct 07, 2009 4:13 am 
Post subject: Re: form with multiple submit buttons?

Thank you for the suggestion! As I'm not a programming whiz I have to ask a few more questions about this idea:

1. would I still be changing my "<form action" from
Code:
admin_auction_offer.$phpEx

To
Code:
admin_auction_offer.$phpEx?mode=mode-name


2. For my "<input name=" submit button code on the form would I use a structure like this:
Code:
name="submit_{offer.AUCTION_OFFER_ID}"

where the {} would contain the unique line number.
How would I write/include the part for [$i] from your suggestion?

3. Assuming in question 1 the answer is no, and I should have action reference the .php page only, without any reference to the mode, in question 2, should my {} variable reference the full URL with mode and line number instead, like this:
Code:
name="submit_{offer.S_ADMIN_OFFER_EDIT_SUBMIT}"

where
Code:
'S_ADMIN_OFFER_EDIT_SUBMIT' => append_sid("admin_auction_offer.$phpEx?" . POST_AUCTION_OFFER_URL . "=" . $offer_rowset[$i]['PK_auction_offer_id'] . "&mode=admin_offer_edit"),


4. Where in your code below should I reference my "mode", example:
Code:
if ( $mode == "admin_offer_edit" )


----
Out of interest, in researching possible solutions to my problem I came across "onclick" - could this also be a way of passing the needed variables via the submit button?
Back to top
Ptirhiik
Board Member



Joined: 19 Nov 2008

Posts: 114


flag
PostPosted: Wed Oct 07, 2009 4:37 am 
Post subject: Re: form with multiple submit buttons?

Let's go straight icon_wink.gif:

data from a form can reach the php on two arrays: $HTTP_POST_VARS, and $HTTP_GET_VARS (form & url), depending what you set in the method= of the form tag. Here, I assume it is post (which is the logical choice). When a submit type input is actioned (eg a button), the browser calls the url set in action part of the form tag, as it was define when the page as been displayed. So for the question 1, the answer is no.

For your submit button, you have one per action right ? So just name them according to the action, eg edit_1, delete_1, etc., and in php set a loop for each button family, with 'edit_' in place of 'submit_', then 'delete_', etc.. Nb.: you can click two buttons at the same time, so you can stop searching as soon as you detect one.
Back to top
guyb
Board Member



Joined: 30 Sep 2009

Posts: 11



PostPosted: Wed Oct 07, 2009 4:55 am 
Post subject: Re: form with multiple submit buttons?

Thanks for the clarification about setting the action URL! I understand that in phpbb3 something like that is possible but I wasn't sure about PHPBB2...

Based on what you wrote about not changing the URL of "action=", this is why my present form coding attempts to pass the "mode" and line item number as hidden values (to be actioned server side):
Code:

      <td class="row2"><input type="hidden" name="offer_id" value="{offer.AUCTION_OFFER_ID}" />
      <input type="hidden" name="mode" value="admin_offer_edit" />
      <input type="submit" name="submit" value="{L_ADMIN_AUCTION_OFFER_FIELD_EDIT}" /></td>


I can see the correct values when I do "view source", but somehow on sql debug the line item value is not received. That's why I started this topic in the first place because I thought maybe I needed to do something different than this. In fact when QA-ing my code it seems that "submit" is not sending anything and the "mode" is not being actioned at all...

* I should point out that my line for "mode" has it hardcoded as "admin_offer_edit" - could that be the problem? Do I need extra/different quotation marks on this:
Code:
if ( $mode == "admin_offer_edit" )



Yes, the form action is post, but I only have 1 action button - "submit": the page I'm modding displays data; if I do nothing with it, nothing has to be done, but if I edit one of the fields, I would press the "submit" button at the end of that line to have all the fields in that line UPDATEd in sql.

The way I'm modding the page, I would be able to UPDATE the listings one by one (i.e. no multiple pressing of submit buttons)

I'm attaching a screenshot for how the screen looks



auction-mod-acp.JPG
 Description:
 Filesize:  91.09 KB
 Viewed:  1911 Time(s)

auction-mod-acp.JPG


Back to top
Ptirhiik
Board Member



Joined: 19 Nov 2008

Posts: 114


flag
PostPosted: Wed Oct 07, 2009 5:38 am 
Post subject: Re: form with multiple submit buttons?

The way the form works is not specific to phpBB 2 or 3, it is standard html protocol, so phpbBB 3 has the same constraint icon_wink.gif. The only way to move elsewhere is to use javascript, so to change the browser behaviour. On a side note, avoid using "submit" as name or id for the submit button, prefer ie submit_form: "submit" is reserved by the browser.

So, I get better your problem with your screenshot. Actually, any submit button will validate the form, but only the one pressed will issue into a database update. You script has so to:
// init part:
- load data from database in order to initialize all fields. Put this in an array,

// check part
- if any submit action has been performed (you can test this with storing in an hidden field a mark set to one, and check if it is present at this time: only formular returning to here will have it, meaning a button has been pressed)
--- read all fields from the formular, looping on the array loaded from database, overiding this array of data,
--- detect at each loop if the submit button has been pressed, and store the array index of this loop for further (don't forget to initialize it to false at top of your script),
--- perform checks in order to prepare a list of warnings you will display at end if any,

// validation part
- if you have detected an array index (eg a button pressed, scaned at chek time), and no warnings,
--- do the database update with the array index,
--- add a mark to display further meaning row updated,

// display part
- in all cases,
--- display any warnings,
--- loop on the array to display the data



In addition:
For what I understand about the purpose of this page, you have actually the need of a single global submit button: the easier for the user is to do all his changes, then validate all. At check time, you will have to detect fields that changed, and at validation time do the update for them. It would be smoother for the user avoiding him to press at each row modified the submit button.
Back to top
guyb
Board Member



Joined: 30 Sep 2009

Posts: 11



PostPosted: Wed Oct 07, 2009 6:11 am 
Post subject: Re: form with multiple submit buttons?

I appreciate the time you're taking to explain this to me step by step. My "skills" with php are primitive at best...

The original coding of the .php file was like this (before my modding, not that this changed anything):
- a series of "if" statements for "sort" or "mode", some including sql UPDATEs
- followed by 1 overall sql SELECT of the form screen's data
- followed by 1 template assign vars section


Assuming for simplicity that I still have 1 submit buttom per line (although I have thought of doing what you suggested with 1 overall submit button):

Regarding:
Quote:
// init part:
- load data from database in order to initialize all fields. Put this in an array,


Would I need something like this for my mode, whereby to "initialize" the fields I call again for all the sql data? Below I'm using the same sql SELECT which already exists in the file. I didn't do this till now because I relied on the sql SELECT which was already in the body of the .php file...

Code:
     
if ( $mode == "admin_offer_edit" )
          {
             $offer_id = ( isset($HTTP_GET_VARS[POST_AUCTION_OFFER_URL]) ) ? $HTTP_GET_VARS[POST_AUCTION_OFFER_URL] : $HTTP_POST_VARS[POST_AUCTION_OFFER_URL];

     // START Grab all the offer-data
     $sql = "SELECT DISTINCT t.*,
                    u.username,
                    u.user_id,
                    u2.username as maxbidder_user_name,
                    u2.user_id as maxbidder_user_id,
                    i.pic_id,
                    acc.auction_account_auction_amount,
                    acc.auction_account_amount_paid
             FROM (" . AUCTION_OFFER_TABLE . " t
             LEFT JOIN " . USERS_TABLE . " u ON u.user_id = t.FK_auction_offer_user_id
             LEFT JOIN " . USERS_TABLE . " u2 ON u2.user_id = t.FK_auction_offer_last_bid_user_id
             LEFT JOIN " . AUCTION_IMAGE_TABLE . " i ON t.pk_auction_offer_id=i.pic_auction_id
             LEFT JOIN " . AUCTION_ACCOUNT_TABLE . " acc ON t.pk_auction_offer_id=acc.fk_auction_offer_id)
             ORDER BY t.auction_offer_time_stop;";
[/code]

What I did have in place until now is this (based partly on what I saw in phpbb2's "profile.php" file vis. "editprofile" mode:
Code:

// THIS FIRST PART DIDN'T SEEM TO HELP ANY:
// if ( isset($HTTP_POST_VARS['submit']) )
// {
     if ( $mode == "admin_offer_edit" )
          {
// THIS PART DOESN'T SEEM TO WORK BUT THE REST OF THIS FILE USES IT SO IT'S MY DEFAULT:
              $offer_id = ( isset($HTTP_GET_VARS[POST_AUCTION_OFFER_URL]) ) ? $HTTP_GET_VARS[POST_AUCTION_OFFER_URL] : $HTTP_POST_VARS[POST_AUCTION_OFFER_URL];
// I TRIED THIS ALTERNATIVE FROM PROFILE.PHP, BUT ALSO NO RESULT
$offer_id = $HTTP_POST_VARS['offer_id']; // otherwise try "mediumint"
//        }            
// STRAIGHT OUT OF PROFILE.PHP:
   $strip_var_list = array('auction_offer_title' => 'auction_offer_title', 'auction_offer_price_start' => 'auction_offer_price_start', 'auction_offer_reserve_factor' => 'auction_offer_reserve_factor', 'auction_offer_direct_sell_price' => 'auction_offer_direct_sell_price', 'auction_offer_shipping_price' => 'auction_offer_shipping_price', 'auction_offer_text' => 'auction_offer_text', 'auction_offer_admins_uncensored_text' => 'auction_offer_admins_uncensored_text', 'auction_offer_comment' => 'auction_offer_comment');

   // Strip all tags from data ... may p**s some people off, bah, strip_tags is
   // doing the job but can still break HTML output ... have no choice, have
   // to use htmlspecialchars ... be prepared to be moaned at.
   while( list($var, $param) = @each($strip_var_list) )
   {
      if ( !empty($HTTP_POST_VARS[$param]) )
      {
         $$var = trim(htmlspecialchars($HTTP_POST_VARS[$param]));
      }
   }
       
// THESE ARE CHECKBOXES:
$auction_offer_special = ( isset($HTTP_POST_VARS['offer_special']) ) ? ( ($HTTP_POST_VARS['offer_special']) ? TRUE : 0 ) : $offer_rowset[$i]['auction_offer_special'];

$auction_offer_on_top = ( isset($HTTP_POST_VARS['offer_on_top']) ) ? ( ($HTTP_POST_VARS['offer_on_top']) ? TRUE : 0 ) : $offer_rowset[$i]['auction_offer_on_top'];

$auction_offer_bold = ( isset($HTTP_POST_VARS['offer_bold']) ) ? ( ($HTTP_POST_VARS['offer_bold']) ? TRUE : 0 ) : $offer_rowset[$i]['auction_offer_bold'];

$sql = "UPDATE " . AUCTION_OFFER_TABLE . "
SET auction_offer_title = '" . $auction_offer_title . "',
auction_offer_text = '" . $auction_offer_text . "',
auction_offer_admins_uncensored_text = '" . $auction_offer_admins_uncensored_text . "',
auction_offer_comment = '" . $auction_offer_comment . "',
auction_offer_price_start = " . doubleval($auction_offer_initial_price) . ",auction_offer_reserve_factor = " . doubleval($auction_offer_reserve_factor) . ",
auction_offer_direct_sell_price = " . $auction_offer_direct_sell_price . ",
auction_offer_shipping_price = " . $auction_offer_shipping_price . ",
auction_offer_special = " . $auction_offer_special . ",
auction_offer_on_top = " . $auction_offer_on_top . ",
auction_offer_bold = " . $auction_offer_bold . "
WHERE PK_auction_offer_id = '" . $offer_id . "'";      

              if( !$result = $db->sql_query($sql) )
                  {
                    message_die(GENERAL_ERROR, "Couldn't update Admin's account changes. Please try again.", "", __LINE__, __FILE__, $sql);
                  } // if                                       
          } // if "mode"
// } // if "submit"


I had originally started the "mode" coding based on the following, which I'd seen elsewhere in the auction mod, but I don't know if this is relevant to my ACP form panel and submit button problem:
Code:

     if ( $mode == "admin_offer_edit" )
    {
    $total_offers = 0;
     while( $row = $db->sql_fetchrow($result) )
     {
         $offer_rowset[] = $row;
         $total_offers++;
     } // while
     $db->sql_freeresult($result);
     $offer_id = ( isset($HTTP_GET_VARS[POST_AUCTION_OFFER_URL]) ) ? $HTTP_GET_VARS[POST_AUCTION_OFFER_URL] : $HTTP_POST_VARS[POST_AUCTION_OFFER_URL];
Back to top
guyb
Board Member



Joined: 30 Sep 2009

Posts: 11



PostPosted: Wed Oct 07, 2009 10:08 am 
Post subject: Re: form with multiple submit buttons?

With your feedback, I had some time to look at the .php files again and see if I could figure out what to do.

The .php file where I'm trying to do the UPDATE is structured like this:
- there are a series of simple "mode" commands which include marking certain variables with a "1", similar to what you suggested above

- below this is the 1 main sql SELECT which calls up all the relevant data on each listed item; just after this is a series of "sort" conditions for re-sorting the output (via text links in the form)

- underneath the SELECT is the following:
Code:

     $total_offers = 0;
     while( $row = $db->sql_fetchrow($result) )
     {
         $offer_rowset[] = $row;
         $total_offers++;
     } // while

     $db->sql_freeresult($result);
     $template->set_filenames(array('body' => 'admin/admin_auction_offer.tpl'));

    if ( $total_offers < 1 )
         {
                 $template->assign_block_vars('no_offer', array(
                     'L_NO_OFFER' => $lang['no_offer_exist']));
         }
    else
         {
             for($i = 0; $i < $total_offers; $i++)
             {


And this is being used to evaluate various conditions from all the previous "mode" and "sort".

- after this is the "$template->assign_block_vars"

So it looks like until now I may have been creating duplicated code instead of relying on the .php page's existing structure, so what I tried to do is this - see if you agree with this/conforms with your idea:

Code:

// THIS IS THE CALL UP FOR MY MODE, UP ABOVE WITH THE OTHER EXISTING ONES:

     if ( $mode == "admin_offer_edit" )
          {
              $offer_id = ( isset($HTTP_GET_VARS[POST_AUCTION_OFFER_URL]) ) ?

$HTTP_GET_VARS[POST_AUCTION_OFFER_URL] : $HTTP_POST_VARS[POST_AUCTION_OFFER_URL];
// OR MAYBE TRY:
// $offer_id = $HTTP_POST_VARS['offer_id'];

              $sql = "UPDATE " . AUCTION_OFFER_TABLE . "
                      Set admin_offer_edit = 1
                      WHERE PK_auction_offer_id='" . $offer_id . "'";

              if( !$result = $db->sql_query($sql) )
                  {
                    message_die(GENERAL_ERROR, "Couldn't mark offer as requested updated.

Please try again.", "", __LINE__, __FILE__, $sql);
                  } // if

          } // if


// ALL THE REST HERE WOULD BE PLACED AS AN "IF" STATEMENT UNDER THE "for($i=1" WHICH I PASTED ABOVE:

                           if ( $offer_rowset[$i]['admin_offer_edit'] = 1 )
                                {
    $auction_offer_title = $HTTP_POST_VARS['auction_offer_title'];
     $auction_offer_text = $HTTP_POST_VARS['auction_offer_text'];
     $auction_offer_admins_uncensored_text = $HTTP_POST_VARS['auction_offer_admins_uncensored_text'];
    $auction_offer_comment = $HTTP_POST_VARS['auction_offer_comment'];
    $auction_offer_price_start = doubleval($HTTP_POST_VARS['auction_offer_price_start']);
    $auction_offer_reserve_factor = doubleval($HTTP_POST_VARS['auction_offer_reserve_factor']);
    $auction_offer_direct_sell_price = doubleval($HTTP_POST_VARS['auction_offer_direct_sell_price']);
    $auction_offer_shipping_price = doubleval($HTTP_POST_VARS['auction_offer_shipping_price']);
     $auction_offer_special = $HTTP_POST_VARS['offer_special'];   
     $auction_offer_on_top = $HTTP_POST_VARS['offer_on_top'];
     $auction_offer_bold = $HTTP_POST_VARS['offer_bold'];

/*OR AM I SUPPOSED TO COMPARE $_POST TO TABLE DATA LIKE HERE?
     $auction_offer_title = ( isset($HTTP_POST_VARS['auction_offer_title']) ) ? $HTTP_POST_VARS['auction_offer_title'] : $offer_rowset[$i]['auction_offer_title'];
     $auction_offer_text = ( isset($HTTP_POST_VARS['auction_offer_text']) ) ? $HTTP_POST_VARS['auction_offer_text'] : $offer_rowset[$i]['auction_offer_text'];
     $auction_offer_admins_uncensored_text = ( isset($HTTP_POST_VARS['auction_offer_admins_uncensored_text']) ) ? $HTTP_POST_VARS['auction_offer_admins_uncensored_text'] : $offer_rowset[$i]['auction_offer_admins_uncensored_text'];
    $auction_offer_comment = ( isset($HTTP_POST_VARS['auction_offer_comment']) ) ? $HTTP_POST_VARS['auction_offer_comment'] : $offer_rowset[$i]['auction_offer_comment'];
    $auction_offer_price_start = ( isset($HTTP_POST_VARS['auction_offer_price_start']) ) ? $HTTP_POST_VARS['auction_offer_price_start'] : $offer_rowset[$i]['auction_offer_price_start'];
    $auction_offer_reserve_factor = ( isset($HTTP_POST_VARS['auction_offer_reserve_factor']) ) ? $HTTP_POST_VARS['auction_offer_reserve_factor'] : $offer_rowset[$i]['auction_offer_reserve_factor'];
    $auction_offer_direct_sell_price = ( isset($HTTP_POST_VARS['auction_offer_direct_sell_price']) ) ? $HTTP_POST_VARS['auction_offer_direct_sell_price'] : $offer_rowset[$i]['auction_offer_direct_sell_price'];
    $auction_offer_shipping_price = ( isset($HTTP_POST_VARS['auction_offer_shipping_price']) ) ? $HTTP_POST_VARS['auction_offer_shipping_price'] : $offer_rowset[$i]['auction_offer_shipping_price'];
   $auction_offer_special = ( isset($HTTP_POST_VARS['offer_special']) ) ? ( ($HTTP_POST_VARS['offer_special']) ? TRUE : 0 ) : $offer_rowset[$i]['auction_offer_special'];
   $auction_offer_on_top = ( isset($HTTP_POST_VARS['offer_on_top']) ) ? ( ($HTTP_POST_VARS['offer_on_top']) ? TRUE : 0 ) : $offer_rowset[$i]['auction_offer_on_top'];
   $auction_offer_bold = ( isset($HTTP_POST_VARS['offer_bold']) ) ? ( ($HTTP_POST_VARS['offer_bold']) ? TRUE : 0 ) : $offer_rowset[$i]['auction_offer_bold'];
*/

/* DO I NEED THE FOLLOWING and WHERE WOULD I PLACE IT?
   $strip_var_list = array('auction_offer_title' => 'auction_offer_title', 'auction_offer_price_start' => 'auction_offer_price_start', 'auction_offer_reserve_factor'
=> 'auction_offer_reserve_factor', 'auction_offer_direct_sell_price' =>
'auction_offer_direct_sell_price', 'auction_offer_shipping_price' =>
'auction_offer_shipping_price', 'auction_offer_text' => 'auction_offer_text', 'auction_offer_admins_uncensored_text' => 'auction_offer_admins_uncensored_text',
'auction_offer_comment' => 'auction_offer_comment');
   while( list($var, $param) = @each($strip_var_list) )
   {
      if ( !empty($HTTP_POST_VARS[$param]) )
      {
         $$var = trim(htmlspecialchars($HTTP_POST_VARS[$param]));
      }
   }
*/

$sql = "UPDATE " . AUCTION_OFFER_TABLE . "
SET auction_offer_title = '" . $auction_offer_title . "',
auction_offer_text = '" . $auction_offer_text . "',
auction_offer_admins_uncensored_text = '" . $auction_offer_admins_uncensored_text . "',
auction_offer_comment = '" . $auction_offer_comment . "',
auction_offer_price_start = " . doubleval($auction_offer_initial_price) . ",
auction_offer_reserve_factor = " . doubleval($auction_offer_reserve_factor) . ",
auction_offer_direct_sell_price = " . $auction_offer_direct_sell_price . ",
auction_offer_shipping_price = " . $auction_offer_shipping_price . ",
auction_offer_special = " . $auction_offer_special . ",
auction_offer_on_top = " . $auction_offer_on_top . ",
auction_offer_bold = " . $auction_offer_bold . "
WHERE PK_auction_offer_id = '" . $offer_id . "'";

                                     if( !$result = $db->sql_query($sql) )                   

                    {                                            message_die(GENERAL_ERROR,

"Couldn't update requested changes.", "", __LINE__, __FILE__, $sql);                         

              }
// CAN I PLACE SUCH CODE HERE OR THIS ONLY FOR "CASE" COMMANDS?
                 $message = $lang['auction_update_saved'] . "<br /><br />" . sprintf($lang['Click_return_auction_index'], "<a href=\"" . append_sid("auction.$phpEx") . "\">", "</a>") . "<br /><br />" . sprintf($lang['Click_return_auction_room'], "<a href=\"" . append_sid("auction_room.$phpEx?ar=" . $HTTP_POST_VARS['auction_room_id']) . "\">", "</a>");           
      message_die(GENERAL_MESSAGE, $message);                                  }


Is this okay?

UPDATE: I gave more thought to the efficiency of using 1 submit button for the whole form. What if I replace the column of submit buttons with checkboxes whereby if checkbox is checked then the single submit button will UPDATE that row? For that to work though, I need a critique of what I wrote above - otherwise I'm still stuck at the base level icon_mrgreen.gif
Back to top
guyb
Board Member



Joined: 30 Sep 2009

Posts: 11



PostPosted: Sun Oct 11, 2009 9:52 am 
Post subject: Re: form with multiple submit buttons?

I designed the form page so that next to each row of data fields there is a checkbox - if I want that line updated, I click the box. At the bottom of the page is 1 single submit button.

The idea is, the checked boxes are supposed to be an array, and pressing the submit button would get all the fields of each row UPDATEd in the sql.

Can anyone critique this if I'm coding the idea correctly?

On the form side, the checkbox looks like this, and passes back the unique item number of the item it relates to:
Code:
<input type="checkbox" name="{S_OFFER_VARIABLE}[]" value="{offer.AUCTION_OFFER_ID}" /></td>


Where the tag above is referenced on the .php page like this:
Code:
'S_OFFER_VARIABLE' => POST_AUCTION_OFFER_URL,



And the server side scripting all takes place within the "mode":
Code:
if ( $mode == "admin_offer_edit" )
   {
      $total_offers_to_update = array();
      if ( isset($HTTP_POST_VARS[POST_AUCTION_OFFER_URL]) || isset($HTTP_GET_VARS[POST_AUCTION_OFFER_URL]) )
      {
         $total_offers_to_update = ( isset($HTTP_POST_VARS[POST_AUCTION_OFFER_URL]) ) ? $HTTP_POST_VARS[POST_AUCTION_OFFER_URL] : $HTTP_GET_VARS[POST_AUCTION_OFFER_URL];
      }
      else
      {
         unset($total_offers_to_update);
      }
      $i = 0;
      while( $i < count($total_offers_to_update) )
      {
         $offer_id = intval($total_offers_to_update[$i]);
$auction_offer_title = $HTTP_POST_VARS['auction_offer_title'];
         $auction_offer_text = $HTTP_POST_VARS['auction_offer_text'];                 
$auction_offer_admins_uncensored_text = $HTTP_POST_VARS
['auction_offer_admins_uncensored_text'];
         $auction_offer_comment = $HTTP_POST_VARS['auction_offer_comment'];
         $auction_offer_price_start = doubleval($HTTP_POST_VARS['auction_offer_price_start']);
         $auction_offer_reserve_factor = doubleval($HTTP_POST_VARS['auction_offer_reserve_factor']);
         $auction_offer_direct_sell_price = doubleval($HTTP_POST_VARS['auction_offer_direct_sell_price']);
         $auction_offer_shipping_price = doubleval($HTTP_POST_VARS['auction_offer_shipping_price']);
         $auction_offer_special = $HTTP_POST_VARS['offer_special'];   
         $auction_offer_on_top = $HTTP_POST_VARS['offer_on_top'];
         $auction_offer_bold = $HTTP_POST_VARS['offer_bold'];

$sql = "UPDATE " . AUCTION_OFFER_TABLE . "
SET auction_offer_title = '" . $auction_offer_title . "',
auction_offer_text = '" . $auction_offer_text . "',
auction_offer_admins_uncensored_text = '" . $auction_offer_admins_uncensored_text . "',
auction_offer_comment = '" . $auction_offer_comment . "',
auction_offer_price_start = " . doubleval($auction_offer_initial_price) . ",         
auction_offer_reserve_factor = " . doubleval($auction_offer_reserve_factor) . ",
auction_offer_direct_sell_price = " . $auction_offer_direct_sell_price . ",
auction_offer_shipping_price = " . $auction_offer_shipping_price . ",
auction_offer_special = " . $auction_offer_special . ",
auction_offer_on_top = " . $auction_offer_on_top . ",
auction_offer_bold = " . $auction_offer_bold . "
WHERE PK_auction_offer_id = $offer_id";

//  OR CAN I JUST UPDATE THE SQL TABLE DIRECTLY WITH HTTP_POST_VARS DATA?

      if( !$result = $db->sql_query($sql) )
   {
   message_die(GENERAL_ERROR, "Couldn't update requested changes.", "", __LINE__,
__FILE__, $sql);
   }
         unset($total_offers_to_update);
         $i++;
      } // while


What I'm worried about is if I'm scripting the repetition of the array correctly, and whether I'm assigning the values correctly to the SQL table...
Back to top
Display posts from previous:   
Register or Login to Post    Index » MOD Writing  Previous TopicPrint TopicNext Topic
Page 1 of 1 All times are GMT - 4 Hours
 
Jump to:  

Index • About • FAQ • Rules • Privacy • Search •  Register •  Login 
Not affiliated with or endorsed by the phpBB Group
Powered by phpBB2 © phpBB Group
Generated in 0.1476 seconds using 18 queries. (SQL 0.0254 Parse 0.0109 Other 0.1113)
phpBB Customizations by the phpBBDoctor.com
Template Design by DeLFlo and MomentsOfLight.com Moments of Light Logo