瀏覽代碼

Make all submit button names unique on compose screen

pdontthink 16 年之前
父節點
當前提交
b69961cfe0
共有 5 個文件被更改,包括 44 次插入4 次删除
  1. 1 0
      ChangeLog
  2. 36 0
      functions/forms.php
  3. 3 1
      src/compose.php
  4. 3 2
      templates/default/compose_body.tpl
  5. 1 1
      templates/default/compose_buttons.tpl

+ 1 - 0
ChangeLog

@@ -267,6 +267,7 @@ Version 1.5.2 - SVN
     option widgets.
     option widgets.
   - Add informational type option widget
   - Add informational type option widget
   - Add password type option widget
   - Add password type option widget
+  - Make all submit button names unique on compose screen
 
 
 Version 1.5.1 (branched on 2006-02-12)
 Version 1.5.1 (branched on 2006-02-12)
 --------------------------------------
 --------------------------------------

+ 36 - 0
functions/forms.php

@@ -336,3 +336,39 @@ function addForm($sAction, $sMethod = 'post', $sName = '', $sEnctype = '', $sCha
     return $oTemplate->fetch('form.tpl');
     return $oTemplate->fetch('form.tpl');
 }
 }
 
 
+/**
+  * Creates unique widget names
+  *
+  * Names are formatted as such: "send1", "send2", "send3", etc.,
+  * where "send" in this example is what was given for $base_name
+  *
+  * @param string  $base_name    The name upon which to base the
+  *                              returned widget name.
+  * @param boolean $return_count When TRUE, this function will
+  *                              return the last number used to
+  *                              create a widget name for $base_name
+  *                              (OPTIONAL; default = FALSE).
+  *
+  * @return mixed When $return_output is FALSE, a string containing
+  *               the unique widget name; otherwise an integer with
+  *               the last number used to create the last widget
+  *               name for the given $base_name (where 0 (zero) means
+  *               that no such widgets have been created yet).
+  *
+  * @since 1.4.18 and 1.5.2
+  *
+  */
+function unique_widget_name($base_name, $return_count=FALSE)
+{
+   static $counts = array();
+
+   if (!isset($counts[$base_name]))
+      $counts[$base_name] = 0;
+
+   if ($return_count)
+      return $counts[$base_name];
+
+   ++$counts[$base_name];
+   return $base_name . $counts[$base_name];
+}
+

+ 3 - 1
src/compose.php

@@ -60,7 +60,9 @@ sqsession_unregister('compose_messages');
 $oErrorHandler->setDelayedErrors(true);
 $oErrorHandler->setDelayedErrors(true);
 
 
 /** SESSION/POST/GET VARS */
 /** SESSION/POST/GET VARS */
-sqgetGlobalVar('send', $send, SQ_POST);
+sqgetGlobalVar('send_button_count', $send_button_count, SQ_POST, 1, SQ_TYPE_INT);
+for ($i = 1; $i <= $send_button_count; $i++)
+   if (sqgetGlobalVar('send' . $i, $send, SQ_POST)) break;
 // Send can only be achieved by setting $_POST var. If Send = true then
 // Send can only be achieved by setting $_POST var. If Send = true then
 // retrieve other form fields from $_POST
 // retrieve other form fields from $_POST
 if (isset($send) && $send) {
 if (isset($send) && $send) {

+ 3 - 2
templates/default/compose_body.tpl

@@ -32,11 +32,12 @@ extract($t);
         ?>
         ?>
  <tr>
  <tr>
   <td class="bottomSend">
   <td class="bottomSend">
-   <input type="submit" name="send" value="<?php echo _("Send"); ?>" />
+   <input type="submit" name="<?php echo unique_widget_name('send'); ?>" value="<?php echo _("Send"); ?>" />
   </td>
   </td>
  </tr>
  </tr>
         <?php
         <?php
     }
     }
  ?>
  ?>
 </table>
 </table>
-</div>
+</div>
+<input type="hidden" name="send_button_count" value="<?php echo unique_widget_name('send', TRUE); ?>" />

+ 1 - 1
templates/default/compose_buttons.tpl

@@ -70,7 +70,7 @@ extract($t);
         <?php
         <?php
     }
     }
    ?>
    ?>
-   <input type="submit" name="send" value="<?php echo _("Send"); ?>" />&nbsp;
+   <input type="submit" name="<?php echo unique_widget_name('send'); ?>" value="<?php echo _("Send"); ?>" />&nbsp;
    <?php if (!empty($plugin_output['compose_button_row'])) echo $plugin_output['compose_button_row']; ?>
    <?php if (!empty($plugin_output['compose_button_row'])) echo $plugin_output['compose_button_row']; ?>
   </td>
   </td>
  </tr>
  </tr>