Form with multiple submit buttons?

Discuss the development of future releases of phpBB (phpBB 3.x minor releases) and MODing/Coding related questions.
Post Reply
guyb
New member
New member
Posts: 17
Joined: 30 Sep 2009, 08:21

Form with multiple submit buttons?

Post by guyb »

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

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 (i.e. not for the whole form and all of the data it displays).

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: Select all

<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?)
User avatar
Obsidian
Supporter
Supporter
Posts: 736
Joined: 13 May 2008, 15:20
Real name: Damian
Contact:

Re: Form with multiple submit buttons?

Post by Obsidian »

guyb wrote:a) add the "mode" value to the form action URL (because it's always the same mode if the submit button is pressed), and


This is what is done with phpBB3, so I would recommend this method.

guyb wrote:b) on the "submit" button, to submit the item number there (so name="offer_id" and value="{offer.AUCTION_OFFER_ID}")


That wouldn't work. Submit only returns a boolean value via $_POST data. The value attribute of the submit button is only for the label of it, nothing more.
guyb
New member
New member
Posts: 17
Joined: 30 Sep 2009, 08:21

Re: Form with multiple submit buttons?

Post by guyb »

In the last couple of days I've tried to get the form and the server side scripting to work. The form is presently designed to show 1 listed item per row with a checkbox at the end of each line. If the box is ticked, the 1 main "submit" button is supposed to take that row into account when UPDATing the sql table...

...only that the updates are not working! I can see the correct present data, but I cannot make edits and updates. I don't even receive error messages.

Here's what I have:

This is the template code

Code: Select all

<h1>{L_ADMIN_OFFER}</h1> 

<P>{L_ADMIN_OFFER_EXPLAIN}</p>

<br>

<br>

<table>
     <tr>
          <td>
               <a href="{U_AUCTION_OFFER_SORT_JUST_NOT_PAID}" class="gensmall">{L_AUCTION_OFFER_SORT_JUST_NOT_PAID}</a><br>
               <a href="{U_AUCTION_OFFER_SORT_JUST_PAID}" class="gensmall">{L_AUCTION_OFFER_SORT_JUST_PAID}</a><br>
          </td>
     </tr>
</table>

<br>

<form enctype="multipart/form-data" method="post" action="{S_ADMIN_OFFER_EDIT}">

<table cellspacing="1" cellpadding="4" border="0" align="center" class="forumline" width="200%">

    <tr>

        <td class="row1" align="center">{L_AUCTION_OFFER_ID}</td>
        <td class="row1" align="center"><a href="{U_AUCTION_OFFER_SORT_TITLE}" class="gensmall">{L_AUCTION_OFFER_TITLE}</a></td>
        <td class="row1" align="center">{L_AUCTION_OFFER_PRICE_START}</td>
        <td class="row1" align="center">{L_AUCTION_OFFER_RESERVE_FACTOR}</td>
        <td class="row1" align="center">{L_AUCTION_OFFER_DIRECT_SELL}</td>
        <td class="row1" align="center">{L_AUCTION_OFFER_SHIPPING_PRICE}</td>
        <td class="row1" align="center"><a href="{U_AUCTION_OFFER_SORT_PAID}" class="gensmall">{L_AUCTION_OFFER_PAID}</a></td>
        <td class="row1" align="center">{L_AUCTION_OFFER_MARK_PAID}</td>
        <td class="row1" align="center"><a href="{U_AUCTION_OFFER_SORT_USERNAME}" class="gensmall">{L_AUCTION_OFFER_OFFERER}</a></td>
        <td class="row1" align="center">{L_AUCTION_OFFER_VIEWS}</td>
        <td class="row1" align="center">{L_AUCTION_OFFER_PICTURE}</td>
        <td class="row1" align="center">{L_AUCTION_OFFER_SPECIAL}</td>
        <td class="row1" align="center">{L_AUCTION_OFFER_BOLD}</td>
        <td class="row1" align="center">{L_AUCTION_OFFER_ON_TOP}</td>
        <td class="row1" align="center"><a href="{U_AUCTION_OFFER_SORT_TIME}" class="gensmall">{L_AUCTION_OFFER_TIME_STOP}</a></td>
        <td class="row1" align="center">{L_AUCTION_OFFER_DELETE}</td>
        <td class="row1" align="center">{L_AUCTION_OFFER_TEXT}</td>
        <td class="row1" align="center">{L_AUCTION_OFFER_ADMINS_UNCENSORED_TEXT}</td>
        <td class="row1" align="center">{L_AUCTION_OFFER_COMMENT}</td>
   <td class="row1" align="center">{L_ADMIN_AUCTION_OFFER_FIELD_EDIT}</td>

    </tr>

    <!-- BEGIN no_offer -->

    <tr>

        <td class="row1" align="center" colspan="21">{no_offer.L_NO_OFFER}</td>

    </tr>

    <!-- END no_offer -->

    <!-- BEGIN offer -->

    <tr>

        <td class="row2"><a href="{offer.U_AUCTION_OFFER_VIEW}" target="_blank" class="gensmall">{offer.AUCTION_OFFER_ID}</a></td>
        <td class="row2" align="center"><textarea rows="2" cols="30" class="post" type="text" name="auction_offer_title" maxlength="255" size="255" />{offer.AUCTION_OFFER_TITLE}</textarea></td>
        <td class="row2" align="center"><input type="text" class="post" name="auction_offer_price_start" size="10" maxlength="10" value="{offer.AUCTION_OFFER_PRICE_START}" /></td>
        <td class="row2" align="center"><input type="text" class="post" name="auction_offer_reserve_factor" size="10" maxlength="10" value="{offer.AUCTION_OFFER_RESERVE_FACTOR}" /></td>
        <td class="row2" align="center"><input type="text" class="post" name="auction_offer_direct_sell_price" size="10" maxlength="10" value="{offer.AUCTION_OFFER_DIRECT_SELL_PRICE}" /></td>
        <td class="row2" align="center"><input type="text" class="post" name="auction_offer_shipping_price" size="10" maxlength="10" value="{offer.AUCTION_OFFER_SHIPPING_PRICE}" /></td>
        <td class="row2" align="center">{offer.AUCTION_OFFER_PAID}</td>
        <td class="row2"><a href="{offer.U_AUCTION_OFFER_MARK_PAID}" class="gensmall">{offer.L_AUCTION_OFFER_MARK_PAID}</a></td>
        <td class="row2" align="center">{offer.AUCTION_OFFER_OFFERER}</td>
        <td class="row2" align="center">{offer.AUCTION_OFFER_VIEWS}</td>
        <td class="row2" align="center">{offer.AUCTION_OFFER_PICTURE}</td>
      <td class="row2" align="center"><input type="checkbox" name="offer_special" {offer.AUCTION_OFFER_SPECIAL_CHECKED}/></td>
        <td class="row2" align="center"><input type="checkbox" name="offer_bold" {offer.AUCTION_OFFER_BOLD_CHECKED} /></td>
        <td class="row2" align="center"><input type="checkbox" name="offer_on_top" {offer.AUCTION_OFFER_ON_TOP_CHECKED} /></td>
        <td class="row2">{offer.AUCTION_OFFER_TIME_END}</td>
        <td class="row2"><a href="{offer.U_AUCTION_OFFER_DELETE}" class="gensmall">{L_AUCTION_OFFER_DELETE}</a></td>
        <td class="row2" align="center"><textarea rows="2" cols="40" class="post" type="text" name="auction_offer_text" maxlength="255" size="255" />{offer.AUCTION_OFFER_TEXT}</textarea></td>
        <td class="row2" align="center"><textarea rows="2" cols="40" class="post" type="text" name="auction_offer_admins_uncensored_text" maxlength="200" size="200" />{offer.AUCTION_OFFER_ADMINS_UNCENSORED_TEXT}</textarea></td>
        <td class="row2" align="center"><textarea rows="2" cols="40" class="post" type="text" name="auction_offer_comment" maxlength="255" size="255" />{offer.AUCTION_OFFER_COMMENT}</textarea></td>
      <td class="row2"><input type="hidden" name="offer_id" value="{offer.AUCTION_OFFER_ID}" />
      <input type="checkbox" name="checked_to_update" value="1" /></td>
    </tr>

    <!-- END offer -->

</table>
<table cellspacing="1" cellpadding="4" border="0" align="center" class="forumline" width="200%">
    <tr>
      <td align="center"><input name="hidSubmit" type="hidden" id="hidSubmit2" value="true">
      <input type="hidden" name="mode" value="admin_offer_edit" />
      <input type="submit" name="submit" value="{L_ADMIN_AUCTION_OFFER_FIELD_EDIT}" /></td>
       
    </tr>
</table>
</form>

<br>

<br>


The line just by the "submit" button:

Code: Select all

       
<input name="hidSubmit" type="hidden" id="hidSubmit2" value="true">

serves as a trigger to process the inputs on the server side.

My full php/server side file is here:

Code: Select all

<?php 
/***************************************************************************
 *                          admin_auction_offer.php
 *                            -------------------
 *   begin                : Jan 2004
 *   copyright            : (C) FR
 *   email                : [email protected]
 *   Last Update          : DEC 2004 - FR
 *
 ***************************************************************************/

/***************************************************************************
 *
 *   This hack is released under the GPL License.
 *   This hack can be freely used, but not distributed, without permission.
 *   Intellectual Property is retained by the author listed above.
 *
 ***************************************************************************/

     define('IN_PHPBB', 1);
     // set admin-navigation
     if( !empty($setmodules) )
          {
               $filename = basename(__FILE__);
               $module['Auction']['a3_offer'] = append_sid($filename);
               return;
          }

     $phpbb_root_path = "./../";
     require($phpbb_root_path . 'extension.inc');
     require('./pagestart.' . $phpEx);
     include($phpbb_root_path . 'includes/functions_selects.'.$phpEx);
     include($phpbb_root_path . 'auction/functions_general.php');
     include($phpbb_root_path . 'auction/auction_constants.php');

     // Start Include language file
     $language = $board_config['default_lang'];
     if( !file_exists($phpbb_root_path . 'language/lang_' . $language . '/lang_auction.'.$phpEx) )
          {
               $language = 'english';
          } // if
     include($phpbb_root_path . 'language/lang_' . $language . '/lang_auction.' . $phpEx);
     // end include language file

     $auction_config_data = init_auction_config();

     // Mode setting
     if( isset($HTTP_POST_VARS['mode']) || isset($HTTP_GET_VARS['mode']) )
          {
               $mode = ( isset($HTTP_POST_VARS['mode']) ) ? $HTTP_POST_VARS['mode'] : $HTTP_GET_VARS['mode'];
               $mode = htmlspecialchars($mode);
          }
     else
          {
               $mode = "";
          } // if

     // Sort setting
     if( isset($HTTP_POST_VARS['sort']) || isset($HTTP_GET_VARS['sort']) )
     {
         $sort = ( isset($HTTP_POST_VARS['sort']) ) ? $HTTP_POST_VARS['sort'] : $HTTP_GET_VARS['sort'];
         $sort = htmlspecialchars($sort);
     }
     else
     {
         $sort = "";
     } // if

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

              // Delete the offer
              $sql = "DELETE FROM " . AUCTION_OFFER_TABLE . "
                      WHERE PK_auction_offer_id='" . $offer_id . "'";

              if( !$result = $db->sql_query($sql) )
                  {
                    message_die(GENERAL_ERROR, "Couldn't delete offer. Please try again.", "", __LINE__, __FILE__, $sql);
                  } // if

              // Delete all corresponding bids
              $sql = "DELETE FROM " . AUCTION_BID_TABLE . "
                      WHERE FK_auction_bid_offer_id='" . $offer_id . "'";

              if( !$result = $db->sql_query($sql) )
                  {
                    message_die(GENERAL_ERROR, "Couldn't delete corresponding bids. Please try again.", "", __LINE__, __FILE__, $sql);
                  }// if

              // Delete all corresponding watches
              $sql = "DELETE
                      FROM " . AUCTION_WATCHLIST_TABLE . "
                      WHERE FK_auction_offer_id = " . $HTTP_GET_VARS[POST_AUCTION_OFFER_URL];

              if( !($result = $db->sql_query($sql)) )
                   {
                        message_die(GENERAL_ERROR, 'Could not delete offer watchlist data', '', __LINE__, __FILE__, $sql);
                   }

          }// if

     if ( $mode == "delete_all_unpaid" )
          {

                // Get all offer-ids
                // Delete all corresponding bids
                // Delete all offers
          } // if

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

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

              if( !$result = $db->sql_query($sql) )
                  {
                    message_die(GENERAL_ERROR, "Couldn't mark offer paid. Please try again.", "", __LINE__, __FILE__, $sql);
                  } // if

          } // if

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

              $sql = "UPDATE " . AUCTION_OFFER_TABLE . "
                      Set auction_offer_paid = 0
                      WHERE PK_auction_offer_id='" . $offer_id . "'";

              if( !$result = $db->sql_query($sql) )
                  {
                    message_die(GENERAL_ERROR, "Couldn't mark offer paid. Please try again.", "", __LINE__, __FILE__, $sql);
                  } // if
          } // if


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

              // Change Account
              $sql = "UPDATE " . AUCTION_ACCOUNT_TABLE . "
                      Set auction_account_amount_paid=auction_account_auction_amount,
                          auction_account_amount_paid_by=2
                      WHERE FK_auction_offer_id='" . $offer_id . "'";

              if( !$result = $db->sql_query($sql) )
                  {
                    message_die(GENERAL_ERROR, "Couldn't mark offer paid in Account. Please try again.", "", __LINE__, __FILE__, $sql);
                  } // if
          } // if

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

              // Change Account
              $sql = "UPDATE " . AUCTION_ACCOUNT_TABLE . "
                      Set auction_account_amount_paid = 0,
                          auction_account_amount_paid_by=0
                      WHERE FK_auction_offer_id='" . $offer_id . "'";

              if( !$result = $db->sql_query($sql) )
                  {
                    message_die(GENERAL_ERROR, "Couldn't mark offer paid in Account. Please try again.", "", __LINE__, __FILE__, $sql);
                  } // if

          } // if

     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'];
      } // if "mode"
/*       
   $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]));
      }
   }
       
   // Run some validation on the optional fields. These are pass-by-ref, so they'll be changed to empty strings if they fail.       
//    validate_optional_fields($auction_offer_title, $auction_offer_price_start, $auction_offer_reserve_factor, $auction_offer_direct_sell_price, $auction_offer_shipping_price, $auction_offer_text, $auction_offer_admins_uncensored_text, $auction_offer_comment);
       
   $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'];
*/   
       
       
     // 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;";       
       
     if ( $sort == 'title' )
          {
              $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_title;";
          } // if

     if ( $sort == 'username' )
          {
              $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 u.username;";
          } // if

     if ( $sort == 'paid' )
          {
              $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_paid;";
          } // if

     if ( $sort == 'just_paid' )
          {
              $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)
                      WHERE t.auction_offer_paid = 1
                      ORDER BY t.auction_offer_title;";
          } // if

     if ( $sort == 'just_not_paid' )
          {
              $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)
                      WHERE t.auction_offer_paid = 0
                      ORDER BY t.auction_offer_title;";
          }// if

     if( !$result = $db->sql_query($sql) )
            {
                    message_die(GENERAL_ERROR, "Couldn't get all offers", "", __LINE__, __FILE__, $sql);
            }// if

     $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++)
             {
                  if (!$offer_rowset[$i]['auction_offer_paid'] )
                       {
                            $mark = $lang['auction_offer_mark_paid'];
                            $u_mark = append_sid("admin_auction_offer.$phpEx?" . POST_AUCTION_OFFER_URL . "=" . $offer_rowset[$i]['PK_auction_offer_id'] . "&mode=mark_paid");
                            $paid = $lang['auction_offer_not_paid'];
                       }
                  else
                      {
                           if ( $offer_rowset[$i]['auction_account_auction_amount'] > 0 )
                                {
                                     if ( $offer_rowset[$i]['auction_account_auction_amount']>$offer_rowset[$i]['auction_account_amount_paid'] )
                                          {
                                               $mark = $lang['auction_offer_mark_undebit'];
                                               $u_mark = append_sid("admin_auction_offer.$phpEx?" . POST_AUCTION_OFFER_URL . "=" . $offer_rowset[$i]['PK_auction_offer_id'] . "&mode=mark_undebit");
                                               $paid = $lang['auction_offer_debitted'];
                                          }
                                     if ( $offer_rowset[$i]['auction_account_auction_amount']==$offer_rowset[$i]['auction_account_amount_paid'] )
                                          {
                                               $mark = $lang['auction_offer_put_on_debit'];
                                               $u_mark = append_sid("admin_auction_offer.$phpEx?" . POST_AUCTION_OFFER_URL . "=" . $offer_rowset[$i]['PK_auction_offer_id'] . "&mode=mark_debit");
                                               $paid = $lang['auction_offer_undebitted'];
                                          }
                                }
                           else
                                 {
                                     $mark = $lang['auction_offer_mark_unpaid'];
                                     $u_mark = append_sid("admin_auction_offer.$phpEx?" . POST_AUCTION_OFFER_URL . "=" . $offer_rowset[$i]['PK_auction_offer_id'] . "&mode=mark_unpaid");
                                     $paid = $lang['auction_offer_paid'];
                                 }
                    } //else                         
   if ( isset($hidSubmit))
                  {   $total_offers_to_update=count($checked_to_update);
                        for($i=0;$i<$count;$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'];

// A TESTING test:
echo $auction_offer_title;
echo '<br>'.$auction_offer_text;
echo '<br>'.$auction_offer_admins_uncensored_text;
echo '<br>'.$auction_offer_comment;
echo '<br>'.$auction_offer_price_start;
echo '<br>'.$auction_offer_reserve_factor;
echo '<br>'.$auction_offer_direct_sell_price;
echo '<br>'.$auction_offer_shipping_price;
echo '<br>'.$auction_offer_special;
echo '<br>'.$auction_offer_on_top;
echo '<br>'.$auction_offer_bold;
echo '<br>'.$offer_id;
                               
$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);
   }
                               
// A TESTING test:
echo $auction_offer_title;
echo '<br>'.$auction_offer_text;
echo '<br>'.$auction_offer_admins_uncensored_text;
echo '<br>'.$auction_offer_comment;
echo '<br>'.$auction_offer_price_start;
echo '<br>'.$auction_offer_reserve_factor;
echo '<br>'.$auction_offer_direct_sell_price;
echo '<br>'.$auction_offer_shipping_price;
echo '<br>'.$auction_offer_special;
echo '<br>'.$auction_offer_on_top;
echo '<br>'.$auction_offer_bold;
echo '<br>'.$offer_id;                                        } // for                           } // if                           

                 
                 $template->assign_block_vars('offer', array(
                     'L_AUCTION_OFFER_MARK_PAID' => $mark,
                     'U_AUCTION_OFFER_MARK_PAID' => $u_mark,

                     'AUCTION_OFFER_TITLE' => $offer_rowset[$i]['auction_offer_title'],
                     'AUCTION_OFFER_ID' => $offer_rowset[$i]['PK_auction_offer_id'],
                     'AUCTION_OFFER_OFFERER' => $offer_rowset[$i]['username'],
                     'AUCTION_OFFER_VIEWS' => $offer_rowset[$i]['auction_offer_views'],
                     'AUCTION_OFFER_PRICE_START' => $offer_rowset[$i]['auction_offer_price_start'],
                     'AUCTION_OFFER_RESERVE_FACTOR' => $offer_rowset[$i]['auction_offer_reserve_factor'],
                     'AUCTION_OFFER_DIRECT_SELL_PRICE' => $offer_rowset[$i]['auction_offer_direct_sell_price'],
                     'AUCTION_OFFER_SHIPPING_PRICE' => $offer_rowset[$i]['auction_offer_shipping_price'],
                     'AUCTION_OFFER_BOLD_CHECKED' => ( $offer_rowset[$i]['auction_offer_bold']) ? "checked=\"checked\"" : "",
                     'AUCTION_OFFER_ON_TOP_CHECKED' => ( $offer_rowset[$i]['auction_offer_on_top']) ? "checked=\"checked\"" : "",
                     'AUCTION_OFFER_SPECIAL_CHECKED' => ( $offer_rowset[$i]['auction_offer_special']) ? "checked=\"checked\"" : "",
                     'AUCTION_OFFER_PICTURE' => ( $offer_rowset[$i]['pic_id'] ) ? "X" : "",
                     'AUCTION_OFFER_SELL_ON_FIRST' => ( $offer_rowset[$i]['auction_offer_direct_sell_price']<>0 )  ? "X" : "",
                     'AUCTION_OFFER_PAID' => $paid,
                     'AUCTION_OFFER_TIME_END' => create_date("m/d/Y - h:i:s", $offer_rowset[$i]['auction_offer_time_stop'], $board_config['board_timezone']),
                     'AUCTION_OFFER_TEXT' => $offer_rowset[$i]['auction_offer_text'],               
                     'AUCTION_OFFER_ADMINS_UNCENSORED_TEXT' => $offer_rowset[$i]['auction_offer_admins_uncensored_text'],               
                     'AUCTION_OFFER_COMMENT' => $offer_rowset[$i]['auction_offer_comment'],

                     'COUPON_USER_CREATED' => $coupon_rowset[$i]['coupon_creator'],
                     'COUPON_DATE_USED' => ( $coupon_rowset[$i]['auction_coupon_date_used']>0 ) ? create_date("m/d/Y - h:i:s", $coupon_rowset[$i]['auction_coupon_date_used'], $board_config['board_timezone']) : $lang['coupon_not_used'],
                     'COUPON_USER_USED' => ( $coupon_rowset[$i]['coupon_user']<>"" ) ? $coupon_rowset[$i]['coupon_user'] : $lang['coupon_not_used'],

                     'U_AUCTION_OFFER_VIEW' => append_sid("../auction_offer_view.$phpEx?" . POST_AUCTION_OFFER_URL . "=" . $offer_rowset[$i]['PK_auction_offer_id']),
                     'U_AUCTION_OFFER_DELETE' => append_sid("admin_auction_offer.$phpEx?" . POST_AUCTION_OFFER_URL . "=" . $offer_rowset[$i]['PK_auction_offer_id'] . "&mode=delete")));
             } // for
          } // if


     $template->assign_vars(array(
            'L_ADMIN_OFFER' => $lang['offer_admin'],
            'L_AUCTION_OFFER_ID' => $lang['auction_offer_id'],
            'L_ADMIN_OFFER_EXPLAIN' => $lang['offer_admin_explain'],
            'L_AUCTION_OFFER_TITLE' => $lang['auction_offer_title'],
            'L_AUCTION_OFFER_TIME_STOP' => $lang['auction_offer_time_stop'],
            'L_AUCTION_OFFER_PAID' => $lang['auction_offer_paid_status'],
            'L_AUCTION_OFFER_ON_TOP' => $lang['auction_offer_on_top_short'],
            'L_AUCTION_OFFER_PICTURE' => $lang['auction_offer_picture_short'],         
            'L_AUCTION_OFFER_PRICE_START' => $lang['auction_offer_price_start_short'],         
            'L_AUCTION_OFFER_RESERVE_FACTOR' => $lang['auction_offer_reserve_factor_short'],         
            'L_AUCTION_OFFER_DIRECT_SELL' => $lang['auction_offer_direct_sell_short'],         
            'L_AUCTION_OFFER_SHIPPING_PRICE' => $lang['auction_offer_shipping_price_short'],
            'L_AUCTION_OFFER_VIEWS' => $lang['auction_offer_views_short'],
            'L_AUCTION_OFFER_SPECIAL' => $lang['auction_offer_special_short'],
            'L_AUCTION_OFFER_BOLD' => $lang['auction_offer_bold_short'],
            'L_AUCTION_OFFER_SELL_ON_FIRST' => $lang['auction_offer_sell_on_comment_short'],
            'L_AUCTION_OFFER_OFFERER' => $lang['auction_offer_offerer'],
            'L_AUCTION_OFFER_DELETE' => $lang['auction_offer_delete'],
            'L_AUCTION_OFFER_MARK_PAID' => $lang['auction_offer_function'],
            'L_AUCTION_OFFER_DELETE' => $lang['auction_offer_delete'],
            'L_AUCTION_OFFER_SORT_JUST_PAID' => $lang['auction_offer_sort_just_paid'],
            'L_AUCTION_OFFER_SORT_JUST_NOT_PAID' => $lang['auction_offer_sort_just_not_paid'],
            'L_ADMIN_AUCTION_OFFER_FIELD_EDIT' => $lang['admin_auction_offer_field_edit'],
            'L_AUCTION_OFFER_TEXT' => $lang['auction_offer_text_short'],
            'L_AUCTION_OFFER_ADMINS_UNCENSORED_TEXT' => $lang['auction_offer_admins_uncensored_text_short'],
            'L_AUCTION_OFFER_COMMENT' => $lang['auction_offer_comment_short2'],
         
            'L_COUPON_USER_CREATED' => $lang['coupon_user_created'],
            'L_COUPON_DATE_USED' => $lang['coupon_date_used'],
            'L_COUPNG_USER_USED'=> $lang['coupon_user_used'],
            'L_COUPON_CREATE' => $lang['coupon_create'],
            'L_CHOOSE_COUPON_TYPE' => $lang['coupon_choose_type'],

            'S_AUCTION_COUPON_ACTION' => append_sid("admin_auction_coupon.$phpEx?mode=create"),
         'S_ADMIN_OFFER_EDIT' => append_sid("admin_auction_offer.$phpEx"),
            'COUPON_LIST_DD' => $coupon_list_dd,
            'U_AUCTION_OFFER_SORT_TITLE' => append_sid("admin_auction_offer.$phpEx?sort=title"),
            'U_AUCTION_OFFER_SORT_USERNAME' => append_sid("admin_auction_offer.$phpEx?sort=username"),
            'U_AUCTION_OFFER_SORT_PAID' => append_sid("admin_auction_offer.$phpEx?sort=paid"),       
            'U_AUCTION_OFFER_SORT_JUST_PAID' => append_sid("admin_auction_offer.$phpEx?sort=just_paid"),
            'U_AUCTION_OFFER_SORT_JUST_NOT_PAID' => append_sid("admin_auction_offer.$phpEx?sort=just_not_paid"),
            'U_AUCTION_OFFER_SORT_TIME' => append_sid("admin_auction_offer.$phpEx")));


      $template->pparse("body");
      include('./page_footer_admin.'.$phpEx);
     
?>



Some pointers to the php code:

* this is the start of my modded "mode" (including a commented out section from profile.php regarding stripping of variables - not sure if needed)

Code: Select all

     if ( $mode == "admin_offer_edit" ) 


* this is my modded code for where the form's altered data should be processed and UPDATEd. "hidSubmit" is that line of hidden output next to the "submit" button. If this has a value, then some kind of a form page update is supposed to take place:

Code: Select all

if ( isset($hidSubmit)) 


* this is the "action" callup for the form page:

Code: Select all

          
'S_ADMIN_OFFER_EDIT' => append_sid("admin_auction_offer.$phpEx"),



Any help would be *greatly* appreciated!
Attachments
auction-mod-acp2.JPG
User avatar
Obsidian
Supporter
Supporter
Posts: 736
Joined: 13 May 2008, 15:20
Real name: Damian
Contact:

Re: Form with multiple submit buttons?

Post by Obsidian »

I'll look into this later.

One thing I did notice, though, is that hack is violating the GPL. The hack's file states "This hack can be freely used, but not distributed, without permission. "
The GPL version 2 (which is what phpBB is licensed under, and all derivatives and other works based on phpBB must use the same license as per the license itself) explicitly states that there cannot be any restrictions on distribution.
guyb
New member
New member
Posts: 17
Joined: 30 Sep 2009, 08:21

Re: Form with multiple submit buttons?

Post by guyb »

Well, if phpbb-auction.com's support is anything to go by, also their support with this mod is "restricted" :mrgreen:

They'd be best able to help me modding their mod, but I can't get responses within a reasonable time...
guyb
New member
New member
Posts: 17
Joined: 30 Sep 2009, 08:21

Re: Form with multiple submit buttons?

Post by guyb »

I tried to solve my problem again and this time I check code from a mod call "User list 2.0.6c" (it doesn't matter so much which mod it was, just that the User List mod also relies on checked boxes to mark which lines to "action").

The checked boxes have to be in an array :mrgreen: I'd had that impression in my post above but didn't pursue it.

What do you think of the new code below? This time, all the update action takes place within the "mode" and is not scattered throughout the .php file as in the above post.

Part 1: my form template "fixes": I rewrote the code for the checkbox, from this

Code: Select all

<input type="hidden" name="offer_id" value="{offer.AUCTION_OFFER_ID}" /> 
<input type="checkbox" name="checked_to_update" value="1" />


With this, where the checkbox isn't used to determine if it was checked but rather to return the unique item number it related to if it is checked (i.e. I accomplish 2 things with 1 checked box):

Code: Select all

<input type="checkbox" name="{S_OFFER_VARIABLE}[]" value="{offer.AUCTION_OFFER_ID}" /></td>


Where the following tag is defined in the .php file as:

Code: Select all

'S_OFFER_VARIABLE' => POST_AUCTION_OFFER_URL,



Part 2: the server side scripting:

Code: Select all

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



One of my concerns is if I'm scripting the repeating loop of the array correctly, and if I'm writing the variables correctly for the SQL update...

------
Update:
In doing QA I'm getting sql debugging errors like this:

Code: Select all

DEBUG MODE

SQL Error : 1064 You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near ' auction_offer_on_top = 1, auction_offer_bold = WHERE PK_au

UPDATE phpbb_auction_offer 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_price_start = 0, auction_offer_reserve_factor = 0, auction_offer_direct_sell_price = 0, auction_offer_shipping_price = 0, auction_offer_special = , auction_offer_on_top = 1, auction_offer_bold = WHERE PK_auction_offer_id ='249'

Line : 233
File : admin_auction_offer.php


On the one hand the routine does recognize the offer id number and my checkbox selection of "auction on top", but on the other it's not recognizing any text or numbers I entered. In the above example, the routine is ignoring those edits and instead assigning the variable names (i.e. "auction offer title") to the field itself in some cases - although this is not getting UPDATEd in sql anyway. That said, my code isn't suppose to cause the variable name to be used as field data...

When I test my code on an article whose details were overwritten in previous QA (i.e. all the fields got blanked), the debugger "sees" everything I enter but still yields a debug error; when I QA the code as above, on an item that has existing text, I'm unable to overwrite it (unless apparently its a checkbox).

I tried this:

Code: Select all

      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 = " . doubleval($auction_offer_direct_sell_price) . ",
auction_offer_shipping_price = " . doubleval($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 . "'";


And then I tried this:

Code: Select all

      while( $i < count($total_offers_to_update) )
      {
         $offer_id = intval($total_offers_to_update[$i]);
    $auction_offer_title = ( isset($HTTP_POST_VARS['auction_offer_title']) ) ? $HTTP_POST_VARS['auction_offer_title'] : $HTTP_GET_VARS['auction_offer_title'];
    $auction_offer_text = ( isset($HTTP_POST_VARS['auction_offer_text']) ) ? $HTTP_POST_VARS['auction_offer_text'] : $HTTP_GET_VARS['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'] : $HTTP_GET_VARS['auction_offer_admins_uncensored_text'];
   $auction_offer_comment = ( isset($HTTP_POST_VARS['auction_offer_comment']) ) ? $HTTP_POST_VARS['auction_offer_comment'] : $HTTP_GET_VARS['auction_offer_comment'];
   $auction_offer_price_start = ( isset($HTTP_POST_VARS['auction_offer_price_start']) ) ? $HTTP_POST_VARS['auction_offer_price_start'] : $HTTP_GET_VARS['auction_offer_price_start'];
   $auction_offer_reserve_factor = ( isset($HTTP_POST_VARS['auction_offer_reserve_factor']) ) ? $HTTP_POST_VARS['auction_offer_reserve_factor'] : $HTTP_GET_VARS['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'] : $HTTP_GET_VARS['auction_offer_direct_sell_price'];
   $auction_offer_shipping_price = ( isset($HTTP_POST_VARS['auction_offer_shipping_price']) ) ? $HTTP_POST_VARS['auction_offer_shipping_price'] : $HTTP_GET_VARS['auction_offer_shipping_price'];
   $auction_offer_special = ( isset($HTTP_POST_VARS['offer_special']) ) ? ( ($HTTP_POST_VARS['offer_special']) ? TRUE : 0 ) : $HTTP_GET_VARS['offer_special'];
   $auction_offer_on_top = ( isset($HTTP_POST_VARS['offer_on_top']) ) ? ( ($HTTP_POST_VARS['offer_on_top']) ? TRUE : 0 ) : $HTTP_GET_VARS['offer_on_top'];
   $auction_offer_bold = ( isset($HTTP_POST_VARS['offer_bold']) ) ? ( ($HTTP_POST_VARS['offer_bold']) ? TRUE : 0 ) : $HTTP_GET_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 = " . doubleval($auction_offer_direct_sell_price) . ",
auction_offer_shipping_price = " . doubleval($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 . "'";


But I receive about the same kind of debugging errors either way. On the 1st set of code the checkboxes return a positive value of "on" and on the 2nd set a value of '0' or '1'.

Am I perhaps supposed to just plug the all the "$HTTP_POST_VARS['offer_bold']" variables straight into the SQL table?
guyb
New member
New member
Posts: 17
Joined: 30 Sep 2009, 08:21

Re: Form with multiple submit buttons?

Post by guyb »

:mrgreen: a person reading this thread could skip down to here, since I've managed (with this forum's help) to fix several of the problems mentioned above.

Where I'm getting stuck is this:
a) my form page displays data fields with pre-existing data in uniquely numbered rows
b) if I want to make any changes to a field in a row I have to click a checkbox at the end of that row so that it gets UPDATEd entirely into an sql table - I could click multiple checkboxes and have several rows updated.

The problem is, the "loop" of getting each row updates is messing up: my 1st row seems to be getting overwritten completely with values belonging to my 2nd row. And depending on any tweaks I'm making in the code during QA, sometimes my last row's values overwrite all the previous rows.

Here's what I've scripted (it's brief!):

Code: Select all

     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]);
//HERE FOLLOWS A SERIES OF LINES IN WHICH I RECEIVE DATA FROM THE FORM FIELD, example:
    $auction_offer_title = ( isset($HTTP_POST_VARS['auction_offer_title']) ) ? $HTTP_POST_VARS['auction_offer_title'] : $HTTP_GET_VARS['auction_offer_title'];
   $auction_offer_title = addslashes($auction_offer_title);

// THIS IS FOLLOWED BY THE SQL "UPDATE", and then:

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

//FURTHER DOWN IS THE                  $template->assign_block_vars('offer', array(
// ETC.


The checkbox to have a row UPDATEd looks like this:

Code: Select all

<input type="checkbox" name="{S_OFFER_VARIABLE}[]" value="{offer.AUCTION_OFFER_ID}" /></td>


where S_OFFER_VARIABLE is declared as:

Code: Select all

         'S_OFFER_VARIABLE' => POST_AUCTION_OFFER_URL,


The form page template is populated by an "assign_block_vars" and an "assign_vars"; I put the 'S_OFFER_VARIABLE' declaration in the "assign_vars" section though I'm wondering if my problem may be that it should be in block_vars...

Do you see what may be wrong with my looping of the checkboxes? Should I be using a "for" statement instead of "while"?
guyb
New member
New member
Posts: 17
Joined: 30 Sep 2009, 08:21

Re: Form with multiple submit buttons?

Post by guyb »

:oops: ...can anyone take a moment to see my last post above and critique the code?

I'm stuck trying to get a looping update to work. I'm only able to edit/update the last row displayed in my form screen. If I try updating any row above it, that row gets completely overwritten with the values of the last (bottom) row...
User avatar
Obsidian
Supporter
Supporter
Posts: 736
Joined: 13 May 2008, 15:20
Real name: Damian
Contact:

Re: Form with multiple submit buttons?

Post by Obsidian »

To be honest, I couldn't say.
Post Reply