Mehrere Submitknöpfe bedienen
Tagged:  •    •  

Bis eben stand ich vor der Herrausvorderung aus einer Tabelle mit meheren SUBMIT-Knöpfen die richtige Textbox rauszufischen. Im Prinzip habe ich sowas:

Das Problem besteht nun, das der Submit-Knopf zwar bei den POST-Variablen auftaucht, aber immer den Index 0 hat, und ich nicht genau weis welchen Text ich haben will. Abhilfe besorgt man sich indem der Index einfach selbst bestimmt wird und so das richtige Feld ermittelt werden kann:

  1. <table style="border: 1px solid black;">
  2.   <tr>
  3.     <td>
  4.       <input type="text" name="meintext[0]" />
  5.     </td>
  6.     <td>
  7.       <input type="submit" name="submit[0]" value="OK">
  8.     </td>
  9.   </tr>
  10.   <tr>
  11.     <td>
  12.       <input type="text" name="meintext[1]" />
  13.     </td>
  14.     <td>
  15.       <input type="submit" name="submit[1]" value="OK">
  16.     </td>
  17.   </tr>

Und dann zum Beispiel per PHP den Wert rausfinden:

  1. $meintext = $_POST['meintext'][key($_POST['submit'])];

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <ins> <del> <blockquote> <abbr> <br> <pre> <p>
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. Beside the tag style "<foo>" it is also possible to use "[foo]".

More information about formatting options