471,316 Members | 1,563 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,316 software developers and data experts.

Updating a count of checkboxes that are checked

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.

Jul 17 '05 #1
2 3804
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 =--
Jul 17 '05 #2
In article <DV***************@news-binary.blueyonder.co.uk>,
Pete <skredding_no_spam_you_tw@s_netscape.net> wrote:
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.


<input type='submit' value='Send'
onClick="document.form.action='page.php';document. form.submit();" />
<input type='submit' value='Next'
onClick="document.form.action='form2.php';document .form.submit();" />

That should do it. But you should ask in a JavaScript group.

--
Sandman[.net]
Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Pete | last post: by
reply views Thread by willow1480 | last post: by
reply views Thread by dan_williams | last post: by
1 post views Thread by Christian Rühl | last post: by
10 posts views Thread by chimambo | last post: by
14 posts views Thread by zufie | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.