[Pro] Merging form fields

I’ve set up a form with fields stating “item” and “price”. There are about 10 of these.

When the email is received, the fields are shown one above the other. Can I format this so that when received they are beside each other, i.e., item - price, rather than

item
price

Thanks


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

Do you mean to do this in your form handler, so the fields are reported in that order when you get the results, or on the screen (in the browser) so they are laid out in that format for your visitor?

If the former, then you’ll need to edit the form handler (PHP code, if you’re using the PHP Feedback Form Action or the built-in Send Form Action). If the latter, then that’s just a matter of putting those fields together in your table or other layout container.

(just took a look at the output of Send Form) If you’re using that, I doubt that this will be possible without fundamentally rewriting the handler. This handler is extremely carefully written – it does all sorts of filtering and testing for malicious input, much of which I didn’t think you could do in PHP at all – and then if that gauntlet is passed, the field names and values are string-concatenated together to form the body of the message.

I guess if I was going to fiddle with this, I would create an array to hold the “cleaned” fields, and add a second line after this one:

$emailBody .= $var['title'] . ": $fieldn";
$cleanFields[$var['title']] = $field;

Then, before the // Sending comment, I would add a loop to re-build the $emailBody string. Let’s say you always include the word item in the “item” fields’ name, and never use that in any of the other field names on the page, so maybe you name them item_1, item_2, price_1, price_2 or whatever.

First, you would need to make sure that your fields would arrive to the server in a predictable order. The easiest way to do that would be to put your fields in a structured layout, either with a table or a list or set of paragraphs. Whatever you do, never just draw the fields on the screen as layered objects – that way lies madness. The important thing to ensure here is that when the fields are sent to your server, the “item” field directly precedes the “price” field that it relates to. Then your loop would look like this:

$emailBody = ''; //clear out what Freeway built
foreach($cleanFields as $key => $val){
	$linebreak = (preg_match('/item/', $key) ? ' - ' : "n";
	$emailBody .= $key . ': ' . $val . $linebreak;
}

So that just duplicates the process of building up the message body, but it substitutes a space-dash-space for a line break after any field whose name contains the letters ‘item’ all together. So modify that to suit how you have actually named your fields – remember, all of this sort of programming is case-sensitive!

What you do after you’ve edited the Action-generated PHP is first, save a copy of the edited handler, and then remove the Action from your page. Finally, use Upload Stuff or Extra Resources or another “uploader” Action to attach the edited handler to the page, and use the Form Setup dialog to point your form to that handler (manually).

Also note (if you’re using Send Form) – the names of the fields are encoded in the handler as a security measure. If you make these edits to the handler, and then disconnect the Action, and finally make some changes to the names of fields in your Freeway form layout, you will have broken the (disconnected copy) handler, because the Action won’t be there to clean up the differences.

Walter

On Jun 28, 2013, at 7:42 AM, Graeme wrote:

I’ve set up a form with fields stating “item” and “price”. There are about 10 of these.

When the email is received, the fields are shown one above the other. Can I format this so that when received they are beside each other, i.e., item - price, rather than

item
price

Thanks


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