This is a discussion on Updating a count of checkboxes that are checked within the PHP Language forums, part of the PHP Programming Forums category; There is a Summary/Example further down... On page one of my site I have a form with some checkboxes ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
There is a Summary/Example further down...
On page one of my site I have a form with some checkboxes and detailed descriptions. When the form is submitted (to page two), the values of the checkboxes are picked up using $_POST and put into session variables. On page two there is another form which is simply a condensed version of the previous one (titles with no descriptions). The checkboxes are named the same on both forms. When page two loads and the posted variables have been put into session variables, my PHP script loops through the session variables and sets the checkboxes on the form to checked where there is a corresponding session variable set. I also have a variable which counts how many of the checkboxes are checked. This is incremented when a session variable that is set (checkbox will be checked) is encountered. So far, so good as this all works with no problems. Now to the problem. I need the users to be able to check/uncheck the checkboxes on page two if they change their mind or made a mistake on page one. If they amend any checkboxes then they can press an Update button to update the count variable. Normally I would achieve this by posting the form back to the page containing the script however once the form on page two is finalised, it needs to be posted to a third page which lays out the data for printing. This does not use form items so the third page is necessary. Example of what I need/Summary of my waffle above: Page 1:User checks 3 boxes and submits form to page 2 Page 2:Item count shows 3 items. User adds 2 more items and presses Update button. Item count now shows 5 items. "New" checkboxes remain checked. Page 2:User is happy and submits form to page 3 Page 3:Form items are converted into printable text/data Is there a way to submit a form to one location if one button is pressed and another location if a second button is pressed? I'm guessing "No" as a form's "action" can only be one location. Any ideas? Thanks in advance, Pete. |
|
|||
|
Pete wrote:
> Is there a way to submit a form to one location if one button is pressed > and another location if a second button is pressed? I'm guessing "No" > as a form's "action" can only be one location. You can name your submit buttons differently and act on which button was pressed. <input type="submit" name="sumbit" value="Preview"> <input type="submit" name="sumbit" value="Go!"> <!-- this misspelling ^^^^^^ was deliberate :) --> and the receiving PHP could do <?php // save $_POST data $_SESSION['postdata'] = $_POST; switch ($_POST['sumbit']) { case 'Preview' : $URL = 'http://www.example.com/page1.php'; break; case 'Go!': $URL = 'http://www.example.com/page2.php'; break; default: $URL = false; } if ($URL) { header('Location: ' . $URL); exit('Redirected <a href="' . $URL . '">here</a>.'); } else { // Uh Oh, someone must have been playing with my form } ?> -- --= my mail box only accepts =-- --= Content-Type: text/plain =-- --= Size below 10001 bytes =-- |