Menu/list question

Seems simple, but I’m missing something!

I want to have a pulldown list of states. So, I insert menu/list item, title=statelist, name=Select a State and define the state entries. For testing I am starting with 3 options:

Choice 1=Alabama, value=AL

Choice 2=Alaska, value=AK

Choice 3=Arizona, value=AR

Based on their choice, I want to print out the value selection (ie AK) on the page. How do I do that? Do I need a GO button for some reason?

I also want to use the value, AL, as a lookup key in a php table. I thought I’d use $statelist, but that doesn’t seem to work.

Gotta be a simple syntax thing I’m missing. Thanks for any/all help in advance.
Jan


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

On Jun 6, 2011, at 7:02 PM, jan smoot wrote:

Seems simple, but I’m missing something!

I want to have a pulldown list of states. So, I insert menu/list
item, title=statelist, name=Select a State and define the state
entries. For testing I am starting with 3 options:

Choice 1=Alabama, value=AL

Choice 2=Alaska, value=AK

Choice 3=Arizona, value=AR

Based on their choice, I want to print out the value selection (ie
AK) on the page. How do I do that? Do I need a GO button for some
reason?

If you are using JavaScript to drive this effect, then no, you don’t
necessarily need the button. You can use the onchange event on the
picker to fire the effect. However, you must have a “null” option as
the default, something like Please choose… as the first option in
the picker, otherwise anyone who selects the first state won’t fire
the onchange event – because the picker hasn’t been changed.

If you had an HTML box on the page somewhere, you could update it with
the value of the picker by using the Extended dialog to add this pair
of options (name and value, respectively)

onchange
document.findElementById('name_of_the_box').innerHTML =
	this.options[this.options.selectedIndex].value

I also want to use the value, AL, as a lookup key in a php table. I
thought I’d use $statelist, but that doesn’t seem to work.

It’s been many years since PHP would just turn a form element value
into a variable like that. You’re going to need to set up a form, and
then in the form handler, you could access it like this (assuming you
set your form to POST rather than GET):

$statelist = $_POST['statelist'];

but only as long as you have named that field statelist using the
third tab from the left in the Inspector. The first tab does nothing
useful in this case.

Walter

Gotta be a simple syntax thing I’m missing. Thanks for any/all help
in advance.
Jan


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Walter,

I think I’d rather have a GO button than Please Choose as the first option. But, when I implement this with a form, it sends an email, which I don’t want or need–but the values look correct. I am using the Multiform action and I get an error (This can not be accessed this way, you need to have an input field named ‘sendtoemail’) if I didn’t include the hidden field sendtoemail with an actual email value. Any more about how to implement with the GO button?

If I were to not use a GO button, not sure how to implement the onchange code.

  1. I put an html item on the page.

  2. selected Item/Extended from the menu

  3. set name=onchange

  4. set value=document.findElementById(‘state’).innerHTML = this.options[this.options.selectedIndex].value where state is the name of my menu/list of states.

  5. nothing shows in the html box, but maybe it’s not supposed to.

I have a bit of php code attempting to print out the state code (it has the open/close php stuff, left that off here)

$statepick = $_POST[‘state’];
echo "State = ",$statepick;

Does not print a value for $statepick.

It’s late for me. Appreciate any feedback Walter.

If you are using JavaScript to drive this effect, then no, you don’t
necessarily need the button. You can use the onchange event on the
picker to fire the effect. However, you must have a “null” option as
the default, something like Please choose… as the first option in
the picker, otherwise anyone who selects the first state won’t fire
the onchange event – because the picker hasn’t been changed.

If you had an HTML box on the page somewhere, you could update it with
the value of the picker by using the Extended dialog to add this pair
of options (name and value, respectively)

onchange
document.findElementById(‘name_of_the_box’).innerHTML =
this.options[this.options.selectedIndex].value

I also want to use the value, AL, as a lookup key in a php table. I
thought I’d use $statelist, but that doesn’t seem to work.

It’s been many years since PHP would just turn a form element value
into a variable like that. You’re going to need to set up a form, and
then in the form handler, you could access it like this (assuming you
set your form to POST rather than GET):

$statelist = $_POST[‘statelist’];

but only as long as you have named that field statelist using the
third tab from the left in the Inspector. The first tab does nothing
useful in this case.

Walter

Gotta be a simple syntax thing I’m missing. Thanks for any/all help
in advance.
Jan


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

On Jun 7, 2011, at 12:00 AM, jan smoot wrote:

Walter,

I think I’d rather have a GO button than Please Choose as the first
option. But, when I implement this with a form, it sends an email,
which I don’t want or need–but the values look correct. I am using
the Multiform action and I get an error (This can not be accessed
this way, you need to have an input field named ‘sendtoemail’) if I
didn’t include the hidden field sendtoemail with an actual email
value. Any more about how to implement with the GO button?

If I were to not use a GO button, not sure how to implement the
onchange code.

  1. I put an html item on the page.

  2. selected Item/Extended from the menu

  3. set name=onchange

  4. set value=document.findElementById(‘state’).innerHTML =
    this.options[this.options.selectedIndex].value where state is the
    name of my menu/list of states.

Not quite. state in this case would be the name of the HTML box where
you want the message to appear. So change that and it might work.

  1. nothing shows in the html box, but maybe it’s not supposed to.

I have a bit of php code attempting to print out the state code (it
has the open/close php stuff, left that off here)

$statepick = $_POST[‘state’];
echo "State = ",$statepick;

Does not print a value for $statepick.

It would, if the form had been posted to this handler code. If the
form hasn’t been submitted, then PHP doesn’t have the values yet. It
sounds to me as though you want to show the result of the picker’s
change on the screen without submitting the form. Is that correct? I’m
not sure I have your use-case figured out yet.

Walter

It’s late for me. Appreciate any feedback Walter.

If you are using JavaScript to drive this effect, then no, you don’t
necessarily need the button. You can use the onchange event on the
picker to fire the effect. However, you must have a “null” option as
the default, something like Please choose… as the first option in
the picker, otherwise anyone who selects the first state won’t fire
the onchange event – because the picker hasn’t been changed.

If you had an HTML box on the page somewhere, you could update it
with
the value of the picker by using the Extended dialog to add this pair
of options (name and value, respectively)

onchange
document.findElementById(‘name_of_the_box’).innerHTML =
this.options[this.options.selectedIndex].value

I also want to use the value, AL, as a lookup key in a php table. I
thought I’d use $statelist, but that doesn’t seem to work.

It’s been many years since PHP would just turn a form element value
into a variable like that. You’re going to need to set up a form, and
then in the form handler, you could access it like this (assuming you
set your form to POST rather than GET):

$statelist = $_POST[‘statelist’];

but only as long as you have named that field statelist using the
third tab from the left in the Inspector. The first tab does nothing
useful in this case.

Walter

Gotta be a simple syntax thing I’m missing. Thanks for any/all help
in advance.
Jan


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Walter,

It would, if the form had been posted to this handler code. If the form hasn’t been submitted, then PHP doesn’t have the values yet. It sounds to me as though you want to show the result of the picker’s change on the screen without submitting the form. Is that correct? I’m not sure I have your use-case figured out yet.

I have an extensive php database of information which needs to be subtotaled and displayed based upon the state selection.

I’ve removed the multiform action and am using the Page/Form Setup feature in Freeway to setup the form. The only hidden field I defined was the form name. I now have the GO button type as submit.

Your analysis is correct–I think, the state selection is not affecting the form results. I am using the PHP Use Include Pages to include MyActiveRecord and my database php calculation code. These two things are clearly not linking up!

The menu/list now has the initial choice of Select State=NA, but I am printing that value ($statepick = $_POST[“state”];
echo "State = ";
echo $statepick;) and it initially prints AL (value of 2nd item in the list). If I change it, it correctly shows the resulting value.

Page is at: http://bankcompensationgroup.com/betasite/stateboli.php if it helps to view it. The Value= at the very top of the screen is generated from within the php include code.

Thanks for your reply Walter.


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Could you please post your PHP form code (I don’t need to see MAR,
just your extension classes) and be sure to elide any database
passwords! Use https://gist.github.com or http://pastie.org to do
this, as large amounts of PHP make the formatter here a little woozy.

One other thing occurs to me – if you’re trying to make the picking
list default to whatever you entered in the form, so that if you
picked Alaska, when the form finished submitting to itself, it read
“Alaska” rather than “Select State” – then try (I emphasize TRY, not
sure if this will work) applying the PHP Form Action (not PHP Feedback
Form Action, mind you) to the page. That will hook any select list and
cause it to look for a global variable of the same name as the select
and auto-default it. But the PHP Form Action was written years before
MAR, and I’m not sure that MAR will expose the right kind of variable
for PFA to use.

Thanks,

Walter

On Jun 7, 2011, at 9:49 AM, jan smoot wrote:

Walter,

It would, if the form had been posted to this handler code. If the
form hasn’t been submitted, then PHP doesn’t have the values yet.
It sounds to me as though you want to show the result of the
picker’s change on the screen without submitting the form. Is that
correct? I’m not sure I have your use-case figured out yet.

I have an extensive php database of information which needs to be
subtotaled and displayed based upon the state selection.

I’ve removed the multiform action and am using the Page/Form Setup
feature in Freeway to setup the form. The only hidden field I
defined was the form name. I now have the GO button type as submit.

Your analysis is correct–I think, the state selection is not
affecting the form results. I am using the PHP Use Include Pages to
include MyActiveRecord and my database php calculation code. These
two things are clearly not linking up!

The menu/list now has the initial choice of Select State=NA, but I
am printing that value ($statepick = $_POST[“state”];
echo "State = ";
echo $statepick;) and it initially prints AL (value of 2nd item in
the list). If I change it, it correctly shows the resulting value.

Page is at: http://bankcompensationgroup.com/betasite/stateboli.php
if it helps to view it. The Value= at the very top of the screen is
generated from within the php include code.

Thanks for your reply Walter.


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Walter,

pastie.org/2032739

This what you’re asking for?

Jan


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Yes. Try this, it should work:

http://pastie.org/2032944

Walter

On Jun 7, 2011, at 11:08 AM, jan smoot wrote:

Walter,

pastie.org/2032739

This what you’re asking for?

Jan


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Walter,

Brilliant! Got it all working. This is the key line…

$statepick = (isset($_POST[‘statepick’])) ? trim(strip_tags($_POST[‘statepick’])) : ‘’;

Can you share with us, so we will continue to learn something! What this line is doing? Why wouldn’t a simple assignment be sufficient? The value is a simple two character string? Why all the fancy footwork?

$statepick = $_POST[‘statepick’];

Walter-can’t thank you enough…
Jan


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

The footwork is there so that $statepick will equal something
regardless of whether or not the POST event has happened. When the
page initially loads, $_POST is an empty array, so the key statepick
doesn’t exist. But an unset value is not the same as equalling an
empty string, and if you have your error reporting level turned up to
E_ALL, you will see that you get a warning if you try to use
$_POST[‘statepick’] before it has a post to draw from.

The trim(strip_tags()) part is there as a very basic guard against
attack. It’s the simple things that bad persons use to break in –
“What could happen? It’s a picking list. I won’t add any guards to
that variable!” – and that’s when they write their own form or use
Firefox Tamper Data to “fuzz” that input.

Walter

On Jun 8, 2011, at 12:22 AM, jan smoot wrote:

Walter,

Brilliant! Got it all working. This is the key line…

$statepick = (isset($_POST[‘statepick’])) ?
trim(strip_tags($_POST[‘statepick’])) : ‘’;

Can you share with us, so we will continue to learn something! What
this line is doing? Why wouldn’t a simple assignment be sufficient?
The value is a simple two character string? Why all the fancy
footwork?

$statepick = $_POST[‘statepick’];

Walter-can’t thank you enough…
Jan


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Walter,
Very helpful. Thank you again Walter for your time and efforts to our community. Hope others learn from this as well.

Jan


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

New but related to this same issue. Now client wants to implement a slightly different interface which has the pull down state list on one page which would then link to the second page with the resulting form answers (the currently implemented page). And the pulldown would remain on the page as well.

So, what I think I need to do is:

  1. Recreate the form on the new page with the pulldown menu/list. (I used the same form name=stateform as on the old page)

  2. Pass the pulldown list result $_POST[‘statepick’] to the second page Not sure how to do this. Do I still need a GO button on the first page? If so, can it also act as a link to the second page or do I also need to add a link? And, how to pass the variable?

I thought maybe by creating the forms with the same name it would recognize the form variable on the second page, but it doesn’t. I see this in the url after my domain name ?statepick=FL&GO=GO&name=stateform

Thought I was all done with this! But, not quite. Thanks for your support.
Jan


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

On Jun 10, 2011, at 12:13 PM, jan smoot wrote:

New but related to this same issue. Now client wants to implement a
slightly different interface which has the pull down state list on
one page which would then link to the second page with the resulting
form answers (the currently implemented page). And the pulldown
would remain on the page as well.

So, what I think I need to do is:

  1. Recreate the form on the new page with the pulldown menu/list. (I
    used the same form name=stateform as on the old page)

No, just include all the form handler code, you can leave the picker
off – that’s just going to confuse things.

  1. Pass the pulldown list result $_POST[‘statepick’] to the second
    page Not sure how to do this. Do I still need a GO button on the
    first page? If so, can it also act as a link to the second page or
    do I also need to add a link? And, how to pass the variable?

Change your Form Setup to point to the page that has the handler on it
(the page that displays the result).

I thought maybe by creating the forms with the same name it would
recognize the form variable on the second page, but it doesn’t. I
see this in the url after my domain name ?
statepick=FL&GO=GO&name=stateform

This is a GET form if it uses these querystring variables, not a POST
form; but your form handler is written to only accept POST variables.
You would need to change $_POST to $_GET in your handler in order to
access those variables.

If you want to be able to respond to input on both GET and POST with
the same handler, just substitute REQUEST everywhere you see POST; so
it reads $statepick = $_REQUEST[‘statepick’] or similar.

Realize though that if you have set your form’s Method to POST, and
its Action attribute to myhandler.php?state=foo, but also have a state
field in your form with a user-entered value of ‘bar’, then when you
look at the value of $_REQUEST[‘state’], it will always be ‘bar’
rather than ‘foo’, and in fact if the user leaves it empty, it will be
equal to an empty string. POST always trumps GET within the same
request, in other words.

Walter

Thought I was all done with this! But, not quite. Thanks for your
support.
Jan


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Walter,

No, just include all the form handler code, you can leave the picker off — that’s just going to confuse things.

Don’t understand this. What do you mean by “leave the picker off?” Leave the GO button off?

When you say “include all the form handler code”… does that mean use freeway’s Form Setup with only the name hidden field as I am now?

Change your Form Setup to point to the page that has the handler on it (the page that displays the result).

How do use the Form Setup to point to a page?

About the GET and POST issue. I had neglected to set the FORM to anything. I corrected that and will use POST.

Thanks Jan


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

On Jun 10, 2011, at 12:54 PM, jan smoot wrote:

Walter,

No, just include all the form handler code, you can leave the
picker off — that’s just going to confuse things.

Don’t understand this. What do you mean by “leave the picker off?”
Leave the GO button off?

No. I am imagining that you will have two pages. One will be the form
page, and the only thing it needs is the picker and the go button. The
other includes all of the the logic to display the results of that
choice.

When you say “include all the form handler code”… does that mean
use freeway’s Form Setup with only the name hidden field as I am now?

On your form page (the page with the picker on it), only include the
picker and the go button. Use the Form Setup dialog’s Action field on
that page to enter the filename of your results page (the one with the
MAR lookup code included into it, and the big table of results). So if
you name that second page results.php, you would enter ‘results.php’
in the Action field in the Form Setup dialog. You should not need any
hidden form elements.

Then, on your results page, you would remove the picker (since you’re
no longer posting to the same page, rather posting from a simple state
picker form to a results page) and you could replace that picker
element on the results page with a text display like this:

<p>Results for: <?= $statepick ?> |
<a href="form.html">Choose Another State</a></p>

The link puts them back to the starting point, where they can choose a
different state.

Walter

Change your Form Setup to point to the page that has the handler on
it (the page that displays the result).

How do use the Form Setup to point to a page?

About the GET and POST issue. I had neglected to set the FORM to
anything. I corrected that and will use POST.

Thanks Jan


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Walter,

Got it! Mostly I needed to add the link in the Form Setup. I didn’t know that’s what that field would do. Now you can select a state on one page, hit GO and it pops to the second page with the correct results. I left the second page exactly as it was and it seems to work fine.

Brilliant…again! Jan


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options