E-mail form and Survey

Hello there,
My goal is to construct a survey with multiple choice questions or maybe fill in the blanks. My host has PHP.

I thought I would start by doing the e-mail form tutorial but my table cells lock up and won’t let me enter a word/value.
Obviously I am doing something wrong

Am I correct that doing a survey really is just an extension of doing the email form, just with more cells and bigger cells so people can enter info or choose an answer from A, B, C, D, E, etc…, then they hit submit?

thanks for help getting me started,
Al


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

What version of Freeway are you using, and is it Pro or Express?

In either one, form fields are not edited by typing into them
directly, but by entering something into the Value field in the
Inspector. But you probably don’t want anything in the Value by
default (when the page loads) – that’s where you want people to type
their data, right?

Walter

On Feb 24, 2009, at 4:39 PM, Al wrote:

My goal is to construct a survey with multiple choice questions or
maybe fill in the blanks. My host has PHP.


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

Hey Walter,
I am on FW 5 Exp.

You got my confusion correct- I don’t know what to type in those value fields for forms: hidden forms, extended etc…,

If I can mix my survey with fill in the blank and multiple choice that would be ideal but if one is easier for a beginner than another then I am game. I can be flexible.
I have yet to find a tutorial that goes into detail on it…

I don’t understand how the table interacts with “extended, hidden,” etc…,
thanks a lot,
Al


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

Extended and Hidden are there if you know that you need them. Otherwise, leave them alone for your first try. There’s an Action for PHP form handling, but it’s Pro-only. So ironically, as an Express user, you’ll have to be smarter than a pro! (Seriously, forms are not all that mind-bending.)

Let’s start with text fields and text areas (they’re the easiest). After you draw or insert a form field in your page, while it’s still selected, look in the Output tab of the inspector (hover slowly over the tabs to see their labels). There are two fields in that tab that are of critical importance: Name and Value.

###Name
No matter what you want the field to be labeled (for the visitor to see), the Name must be a single word (or several words joined by underscores, like ‘first_name’). It must not begin with a numeral, although it may contain a number or two after the first character. It must be a unique name on that page. If you have two fields named ‘foo’, you will only ever receive the value of the second one.

###Value
This can either be blank, or include a bit of code to “play back” whatever the visitor entered into the field. This second option only comes into play if you are using the Post-Back design pattern for your form handler. (What this means is that you post the form to itself, and a handler script within the form does the processing and error-checking. Why would you do this? Because if there are errors, you can re-load the form with all the previous input, so your visitor doesn’t have to re-type anything they already got “right”.) If you are doing this, then you would enter the same value as the Name field, but formatted like this:

<?php echo( $the_field_name ); ?>

…in the Value field.

###Form Setup Dialog
Set the Method to POST, and the Action leave blank (this will POST the form to itself). Don’t worry about the hidden fields, they’re not needed in this example.

###The Form
Make a new form with two text fields (name and email) and one textarea (message). For extra points, add the PHP code above to each field so it’s set to display what your visitor entered. Add a single submit button at the end, and Name that button submit and give it a Value of Submit.

###The Form Handler

From the main menu, choose Page / HTML Markup, then switch the resulting dialog to Before HTML using the picker in its lower-left corner. Paste in the following (note that this relies on you using exactly the names – in lower-case – as I listed above):

<?php
//extract posted values or set defaults
//adjust this array to include the names of YOUR fields
$fields = array('name','email','message');
$_message = '';

if(isset($_POST['submit'])){
    foreach($fields as $field){
        $$field = trim(strip_tags($_POST[$field]));
    }
}else{
    foreach($fields as $field){
        $$field = '';
    }
}
if(isset($_POST['submit'])){
    //basic error checking
    //you could have some fields optional by leaving them out
    $required = array('name','email','message');
    $errors = array();
    foreach($required as $field){
        if(empty($$field)){
            $errors[$field] = ucwords(str_replace('_',' ',$field)) . ' was missing';
        }
    }
    //are there errors?
    if( count($errors) > 0 ){
        foreach($errors as $e){
            $_message .= '<p class="error">' . $e . '</p>';
        }
    }else{
        //no errors, let's e-mail the results
        foreach($fields as $field){
            $_message .= $field . ': ' . $$field . "n";
        }
        mail('your-email-here','Subject Line here',$_message,'From: your-email-here','-fyour-email-here');
    }
}
?>

###Error Reporting
Finally, somewhere on your page where people can see it, place a new Markup Item to display any error messages. Page / Insert / Markup Item (and paste the following code in the dialog that appears):

<?php echo $_message; ?>

When you okay the dialog, you’ll see a 100px-square box in the center of the screen. Resize this and move it to where you want your errors to appear. Nothing will appear if there are no errors, naturally.

###Whew!
A couple of important notes: 1. This will only work with fields named precisely ‘name’,‘email’,‘message’ using the Name field on the Output tab of the Inspector. 2. You must replace ‘your-email-here’ with your actual e-mail address, and at the end of the script, where you see -fyour-email-here – that’s not a typo. Enter (dash)(f) and then type your e-mail address directly following the f with no space between.

Give this a try on a new blank document, make sure your page has a filename that ends in .php, and upload it to a server. (You won’t be able to test this locally, or even see anything in Preview or Preview in Browser except a page full of code.)

After you get this basic example working, you can move on to more elaborate field types, like picking lists and radio buttons and checkboxes.

Walter


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

Hey thanks a bunch Walter. Very excellent.
I am going to get cracking later on it and will post back as soon as I screw something up which should not be long. :slight_smile:
thanks,
Al


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

Great! I thought of one thing to add – at the very end, after the line that starts with mail(…, add one more line directly after that (before the closing bracket):

$_message = 'Your message was sent!';

This will tell you whether the form successfully completed. Another popular thing to do is to redirect to a “Thanks” page. If you want to try that, make a new page called thanks.html in your test document, and instead of the $_message bit above, directly after mail( … ); add:

header('Location: thanks.html');
exit;

You won’t see any message or anything if you do that, so your Thanks page will need to explain that the message was sent.

Walter


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

Walter,
Am I to start by drawing a table then inserting a text field in it or just start with a text field and NO table?

Al


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

Walter this is what I have for the all important email line:

mail(email@hidden,‘Subject Line here’,$_message,‘From: your-email-here’,'-(dash)(f)email@hidden);

I interpreted (Dash)(f) literally and have no spaces
or extra parentheses …

Do I apply the PHP feedback action to the page that I downloaded earlier?

thanks,
Al


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

I would use a table. It ends up being cleaner, code-wise, and easier
for visually-disabled persons like my friend Beverly.

Walter

On Feb 25, 2009, at 10:48 AM, Al wrote:

Walter,
Am I to start by drawing a table then inserting a text field in it
or just start with a text field and NO table?

Al


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

No actions, and where I have (dash)(f) you should put -f.

Walter

On Feb 25, 2009, at 11:10 AM, Al wrote:

Walter this is what I have for the all important email line:

mail(email@hidden,‘Subject Line here’,$_message,‘From: your-
email-here’,'-(dash)(f)email@hidden);

I interpreted (Dash)(f) literally and have no spaces
or extra parentheses …

Do I apply the PHP feedback action to the page that I downloaded
earlier?

thanks,
Al


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

To be completely unequivocal, here’s what it should look like:

http://pastie.org/400011

I’m using Pastie because it won’t strip out a real-looking e-mail
address and confuse things further.

Walter

On Feb 25, 2009, at 2:05 PM, Walter Lee Davis wrote:

I interpreted (Dash)(f) literally and have no spaces
or extra parentheses …


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

Walter,
I Did it without using table - as it doesn’t matter to me what it looks like until I understand how it works.

Ok this is what I have - not sure about spaces or parentheses… I have uploaded and the page doesn’t load.

I named the survey page test.php
so it should be:
mysite.com/index.html/test.php

and have for code :

mail(email@hidden,‘Subject Line here’,$_message,‘From: email@hidden’, 'email@hidden); header(‘Location: thanks.html’);
exit;

}

}
?>

Perhaps I have to “turn on” or initiate PHP from my host Go Daddy?
thanks,
Al


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

make sure you have single-quotes around the e-mail address in the
first argument.

mail(‘email@hidden’,

Walter

On Feb 25, 2009, at 3:46 PM, Al wrote:

Walter,
I Did it without using table - as it doesn’t matter to me what it
looks like until I understand how it works.

Ok this is what I have - not sure about spaces or parentheses… I
have uploaded and the page doesn’t load.

I named the survey page test.php
so it should be:
mysite.com/index.html/test.php

and have for code :

mail(email@hidden,‘Subject Line here’,$_message,'From: email@hidden
', 'email@hidden); header(‘Location: thanks.html’);
exit;

}
}
?>

Perhaps I have to “turn on” or initiate PHP from my host Go Daddy?
thanks,
Al


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

Page doesn’t load when I type it in manually in browser.
I put a button on another page to link to the test page and get :

Parse error: syntax error, unexpected T_STRING in /home/content/h/i/g/highnoonal/html/test.php on line 36

Will follow up with Go Daddy.

Thanks,
Al


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

Can you open the Freeway-generated page in a text editor (even
TextEdit in plain-text mode will work for this) and Pastie the
generated code to me? I have debugging tools here that will make short
work of this, but trying to debug by email is going to get tiring for
both of us. GoDaddy will not help you with this, it’s a programming
error in your page and they are not at fault here. Somewhere, a
quotation mark is missing or something like that, I’m guessing.

Walter

On Feb 25, 2009, at 4:09 PM, Al wrote:

Parse error: syntax error, unexpected T_STRING in /home/content/h/i/
g/highnoonal/html/test.php on line 36


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

I copied the page code from Text edit and sent you an email with in.
Will that work?
thanks,
Al


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

Before you even do that, I have a solution. You copied my code out of
Apple Mail, and pasted it directly into Freeway’s Page / HTML Markup
dialog, didn’t you?

That unfortunately carried over non-breaking spaces in place of normal
spaces, which totally mucks up PHP. Here’s the solution:

Open up the Page / HTML Markup dialog, and use your arrow keys to step
through each line. Delete any space that appears before the beginning
of each line. So if it looks like this:

 if(isset($_POST['submit'])){
     foreach($fields as $field){

(with the leading space before the line that begins ‘foreach…’) just
snug all the lines up to the left. The lack of indenting won’t make
any difference to the PHP code. (Actually, it will, in that it will
suddenly work again.)

Walter

On Feb 25, 2009, at 4:17 PM, Walter Lee Davis wrote:

Can you open the Freeway-generated page in a text editor


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

I copied the code from this site page…

Al


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

That brings the same problem along. Mail and Safari share a text view,
and that’s where the problem starts. It’s a Freeway bug, I’m writing
it up now so it can get fixed. Do try deleting all the leading spaces
and see if it works.

In future, the thing to do (until Freeway fixes this dialog so that it
properly sanitizes the text that gets pasted into it) is to paste the
text into a proper programmer’s editor (with Show Invisibles turned
on) and use find-and-replace to remove non-breaking spaces (which
usually show up as gray bullets when show invisibles is on) and
replace them with normal spaces.

Walter

On Feb 25, 2009, at 4:37 PM, Al wrote:

I copied the code from this site page…

Al


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

Page still doesn’t show up Walter even after aligning it all.
I assume you mean the brackets as well…
Should it look exactly like the code above with the line breaks and spaces between lines - just everything aligned to the left edge?

mysite.com/index/test.php doesn’t work- parse error

Al


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