syntax to use a changing variable in a Radio Button

Is there a syntax that I could use for the having the radio button or drop down menu /list read from a variable or a sting set?

For instance: I have a variable X1 and it value can change. I want to just set the Radio Button to equal ‘X1’.

Is there a way to do this inside of freeway or will I have to hard code it?


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

You can do it in JavaScript or PHP (or another language if your server
supports it). As far as how you add this in Freeway, it depends on how
you are getting this variable, and from where.

Let’s say you have it in a database, and you have a way of getting it
out, so $foo = “bar” (in PHP). What you need to do inside of Freeway
is first, change the filename of the page to end in .php (use the
Inspector). Next, you need to add some code to the head of your page
(or include it from an external file) that sets that value in the
scope of the current page. Something like this, in the Before HTML
section of the Page Markup dialog would do the trick:

<?php
	$foo = 'bar';
	//or more likely...
	require_once('config.inc.php');
	foreach(ActiveRecord::FindAll('parameters') as $parameter){
		${$parameter->name} = $parameter->value;
	}
?>

Then, in the Value field of that form element (third tab from the left
in the Inspector while the form element is selected) enter the proper
code for your server:

<?= $foo ?>

(if you have short tags on)

<?php echo $foo; ?>

(if you don’t).

Once you publish to the server (and view it on the real PHP server),
your form element will have the correct value set to whatever you
defined that variable to equal.

Walter

On Jun 22, 2011, at 6:03 PM, Shane wrote:

Is there a syntax that I could use for the having the radio button
or drop down menu /list read from a variable or a sting set?

For instance: I have a variable X1 and it value can change. I want
to just set the Radio Button to equal ‘X1’.

Is there a way to do this inside of freeway or will I have to hard
code it?


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,

Ok. I see what you are saying 90% here. Here is how I was using the PHP and DB connect:

  1. “PHP include PHP action” to make the PHP header information that is required.
    1.a. I am setting the file name to test.php
  2. “MYSQL Connect action”. to make the DB connection. (I use a read only login to connect)
  3. “MySQL Get Records action” to pull the information into the page and set the variables.
  4. I am also using some of the other PHP actions to setup some of the server side stuff if it comes up in the future. easier to do it now then later.

Now I am at the point where I was going to set values inside of the radio button at the radio button. I have the inspector open and looking at the “Value” box for the radio button. I should be able to have the value set to a variable of my choice brought in through the DB read.

Do i just set it to a variable name? or is there a syntax like [[x1]] that I have to do?

I am having an Apache test server setup tomorrow using the VirtualHostX software on a desktop I have laying around.


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

Yes, just follow the second part of my directions, then. If your
variable is named X1, then in your radio button, in the Inspector, in
the Value field, enter

<?php echo $X1; ?>

all of that, just like that, and you should get the value into the
form element when PHP extracts the value and prints it out as the page
loads. If you view the source in your browser (from the server), you
will see something like this (assuming that $X1 was equal to ‘4 Euros’:

<input type="radio" name="price" value="4 Euros" />

So that gets it into your form, as shown to the browser, and completed
by the user. Next, you have to take this into your form handler (the
page or script that lives at whatever URL you entered into the Action
field in the Form Setup dialog on your page) and get the variables out
again.

Radio buttons are slightly weird compared with other form elements. In
a radio button group, all of the fields are named exactly the same,
and they only vary by their value. So you might have this:

<input type="radio" name="vegetable" value="broccoli" />
<input type="radio" name="vegetable" value="spinach" />
<input type="radio" name="vegetable" value="carrots" />

This ensures that the user can only choose one of the set. When you
get the form contents back at your handler, only one of the three (or
none, if you don’t set a default) will actually be sent to you:

print $_POST['vegetable']; // => 'carrots'

You handle checkboxes in a different manner, because they allow
multiple selection:

<input type="checkbox" name="vegetable[]" value="broccoli" />
<input type="checkbox" name="vegetable[]" value="spinach" />
<input type="checkbox" name="vegetable[]" value="carrots" />

Notice the square brackets at the end of the name attribute – that
tells the browser to send back an array of values for that one
variable name. If you named them all the same thing, and without the
brackets, then you would only get the “last” selected value, no matter
how many were actually selected.

Back at the handler, assuming that two of the three were chosen, you
might see:

print_r($_POST['vegetable']); //=> Array { 0 => 'broccoli', 1 =>  

‘spinach’ }

So you have to handle them differently when reading back the value.
Checkboxes that are not checked are never sent by the browser – so
you can’t look at a form submission and actually know how many
unchecked fields there were, only the checked ones.

Walter

On Jun 22, 2011, at 7:09 PM, Shane wrote:

Walter,

Ok. I see what you are saying 90% here. Here is how I was using
the PHP and DB connect:

  1. “PHP include PHP action” to make the PHP header information that
    is required.
    1.a. I am setting the file name to test.php
  2. “MYSQL Connect action”. to make the DB connection. (I use a
    read only login to connect)
  3. “MySQL Get Records action” to pull the information into the page
    and set the variables.
  4. I am also using some of the other PHP actions to setup some of
    the server side stuff if it comes up in the future. easier to do it
    now then later.

Now I am at the point where I was going to set values inside of the
radio button at the radio button. I have the inspector open and
looking at the “Value” box for the radio button. I should be able
to have the value set to a variable of my choice brought in through
the DB read.

Do i just set it to a variable name? or is there a syntax like
[[x1]] that I have to do?

I am having an Apache test server setup tomorrow using the
VirtualHostX software on a desktop I have laying around.


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 cool.

its the “<?php echo $X1; ?>” that I was looking for. I chose the radio buttons purely to prevent bad selections.

I am working it in with Moo’s Accordion function to dynamically hide selections that can cause conflicts, or allow the customer to increase options in a specific region through the DB. Seems to be working fine, but tomorrow is the day of real testing.


I am going to be asking a similar question about Menu/List fields and how to update them through DB or calculation values.

I am going to split the 2 for future references.


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

You do know you are the bomb? :slight_smile:

I have been reading a large portion of your post to start learning, and finding the damn BIG manual the other night was so helpful too.


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

I learned all this form and server stuff the hard way, starting in
1997 when I got my first Unix server. I can’t tell you the number of
fat books I have read and the number of awful scripts I have coded
before I finally caught on. I’m still learning, too. If I can help, I
will, because other people helped me when I was “coming up”.

Walter

On Jun 22, 2011, at 8:36 PM, Shane wrote:

You do know you are the bomb? :slight_smile:

I have been reading a large portion of your post to start learning,
and finding the damn BIG manual the other night was so helpful too.


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

Sounds like me and the damn PLCs. you know they even change the damn coding between the model numbers??? No improvements, but name changes for some reason.


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