MAR

Using MAR I’m trying to pass the value of a radio button and checkbox (10 of each) but I’m not sure where to place the php variable. Each variable is represented in the db.

Partial:

<input type="radio" name="group1" value="Yes"> Yes
<input type="radio" name="group1" value="No"> No

<input type="checkbox" name="group4" value="Yippee"> Yippee
<input type="checkbox" name="group4" value="WhooHoo"> WhooHoo

For example, in the above code for the radio button “Yes”, no matter where I put the variable <?=h($yes1)?> in the above markup the value does not get passed.

Also, with regard to the controller, although I have working pickers:

$devices = array('Select...','Desktop/Laptop','iPad','iPhone','Android','Other (specify below)');
$device = $mar->device;
$mar->device_picker = SimpleListBox($devices,'device');

I’m not sure how to represent the radio and checkboxes in a similar fashion.

Finally, is tinyint() or Boolean the best Data Type for radio and checkboxes?

Todd


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

Ok, I found and fixed some of my errors so most of the data is now being passed to the db. Here’s what’s left.

The radio buttons and checkboxes still aren’t passing their text (not numerical) values.

New partial:

<input type="radio" id="yes1" name="yes1" value="Yes">Yes
<input type="radio" id="no1" name="no1" value="No"> No

<input type="checkbox" id="store" name="store" value="Store"> Store
<input type="checkbox" id="video" name="video" value="Video Library"> Video library

Todd


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

As you may have found out, setting the Name of a field defines the name of the variable that will be set from it:

<input type="checkbox" name="foo" value="bar" />

will set a variable like this when the form is submitted:

$_REQUEST['foo'] = 'bar'

But in the special case of checkboxes and radio buttons, only the one that’s actually checked gets sent AT ALL.

Now as to the value being set or not, I usually use the tinyint (or boolean, where it exists, not all versions of MySQL have it) to set the value of a yes/no, and to make that work in HTML, I always set the value of the field to 1.

That’s not to say that a checkbox cannot ever be used for anything except a boolean – the type of form element you use to expose an object’s attribute should be driven by the type of data you want to gather and also by the way it’s organized in the user’s mind.

So in the case of your examples here, what form do the $your_object->yes1, $your_object->no1, $your_object->store, and $your_object->video attributes take in your database? That’s where I would start looking when trying to understand why a variable wasn’t persisting.

Walter

On Jan 12, 2013, at 1:01 AM, Todd wrote:

Ok, I found and fixed some of my errors so most of the data is now being passed to the db. Here’s what’s left.

The radio buttons and checkboxes still aren’t passing their text (not numerical) values.

New partial:

<input type="radio" id="yes1" name="yes1" value="Yes">Yes
<input type="radio" id="no1" name="no1" value="No"> No

<input type="checkbox" id="store" name="store" value="Store"> Store
<input type="checkbox" id="video" name="video" value="Video Library"> Video library

Todd


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


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

Cruising along now. Radios and checkboxes making it into the db.

Now for formatting the confirmation email. I have it working fine but there are about 20 fields worth of data I want listed vertically, one entry per line. Right now it sends it on one line so I’ve been trying to insert
tags but they get output along with everything else.

Here’s the default stripped-down version from the model.php:

$body = 'Item 1:' . $this->group1 . 'Item 2:' . $this->group2;

Todd


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

If you are sending plain-text mail, then you want to use Unix newlines instead of br tags to separate lines. If you’re formatting multipart HTML mail, then you must send a plain-text section along with it, so here’s what I usually do to format this sort of list. First, bung everything into an array in the order you want to show it:

$body_parts = array('item 1' => $this->group1, 'item2' => $this->group2, ... );

then filter the array to only show the visible entries:

$intermediate_array = array();
foreach($body_parts as $k => $v){
	if(!empty($v)) $intermediate_array[] = "$k: $v";
}

finally, join that array into a string, separating the lines by newlines:

$body = implode("n", $intermediate_array);

(In case the formatter eats it – and you’re reading this on the Web – there should be a double-quote pair containing a backslash followed immediately by a lower-case n as the first argument to the implode() method. It has to be a double-quote pair, because otherwise it will be entered as a literal backslash-n instead of the meta-character Newline.)

Walter

On Jan 12, 2013, at 9:31 PM, Todd wrote:

Cruising along now. Radios and checkboxes making it into the db.

Now for formatting the confirmation email. I have it working fine but there are about 20 fields worth of data I want listed vertically, one entry per line. Right now it sends it on one line so I’ve been trying to insert
tags but they get output along with everything else.

Here’s the default stripped-down version from the model.php:

$body = 'Item 1:' . $this->group1 . 'Item 2:' . $this->group2;

Todd
http://xiiro.com


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


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

Perfect. Thanks.

Not surprisingly apostrophes are giving me some trouble in the model (below) and the controller (e.g. when defining picker options). I’ve been reading about different ways to escape them with backslashes etc. but it’s not working.

For example in the model:

$body_parts = array('I can't escape an apostrophe' => $this->group1;

Todd
http://xiiro.com


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

Use double-quotes to wrap the key name: "I can't escape an apostrophe". Although I’d be very surprised if the key of an array can contain spaces – that may be your larger issue here. You might have to change the structure so the key is not significant any more:

$body_parts = array(0 => array('I can't escape an apostrophe', $this->group1));

foreach($body_parts as $k => $v){
	if(!empty($v[0])) $intermediate_array[] = $v[0] . ': ' . $v[1];
}

Walter

On Jan 12, 2013, at 10:13 PM, Todd wrote:

Perfect. Thanks.

Not surprisingly apostrophes are giving me some trouble in the model (below) and the controller (e.g. when defining picker options). I’ve been reading about different ways to escape them with backslashes etc. but it’s not working.

For example in the model:

$body_parts = array('I can't escape an apostrophe' => $this->group1;

Todd
http://xiiro.com


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


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

At 22:42 -0500 12/1/13, Walter Lee Davis wrote:

Use double-quotes to wrap the key name: "I can't escape an apostrophe". Although I’d be very surprised if the key of an array
can contain spaces – that may be your larger issue here. You might
have to change the structure so the key is not significant any more:

There’s no reason why an array key shouldn’t contain spaces. The key
is just a sequence of bytes. As long as it’s correctly quoted or in a
variable it will never be parsed into words.

David


David Ledger - Freelance Unix Sysadmin in the UK.
email@hidden
www.ivdcs.co.uk


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

Can a bold style be added to the email formatting?

$body_parts = array('This text should be bold' => $this->group1);

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

Not in plain-text e-mail, no. The only “formatting” you can do is all-caps, underline with hyphens or equals-signs or underscores, etc. This rarely looks good in modern e-mail clients, though, owing to the use of proportional fonts (no way to tell how many hyphens will underline just the word).

If you want to format the message, you will need to create a multipart/mime message, which means creating an HTML version, then a plain-text version, mushing them together in the proper order with the proper headers, and sending that out. It’s a lot of work. I usually use a mail composition package from PHPClasses.org, forget which one. Rails has this all beaten into tiny pieces, no actual effort needed to send multipart mail, and is strips down your .html.erb template to create the text version automatically. You could try doing that by running the strip_tags() function against your HTML. As long as you weren’t also using any entities, you’d get pretty close. If you were using curly-quotes or similar, you’d see the & code ; escapes in your plain-text message part.

Walter

On Jan 13, 2013, at 2:59 PM, Todd wrote:

Can a bold style be added to the email formatting?

$body_parts = array('This text should be bold' => $this->group1);

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


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

Interesting, but that’s a lot of work for little payoff. I’m the only person seeing the emails so it’s not a big deal.

This was an impromptu side project so it was easy to throw together with MAR since I had most everything in place already. That said I’m still working on my Ruby skills so next time I do something like this hopefully I can make the final jump to RoR.

Todd


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