PDA

View Full Version : Guilty but so nearly ecstatic


travisperkins
02-11-2006, 06:11 AM
I have attached a project that contains 5 pages.

Pages 1 and 3 contain just text. Pages 2 and 4 each contain 2 Input Boxes for the user to type in answers to questions.

Input1, Input2, Input3 and Input4

The input is stored in AutoPlay\\Docs
InputText1.txt, InputText2txt, InputText3txt and InputText4txt respectively.

The user can quit the application, come back and amend their input at any time.

When they are happy, the user is to go to Page 5 where there is a Submit Button.

On Click, I want this submit Button to aggregate the data from:
InputText1, InputText2, InputText3 and InputText4

and send it by email to biz@karazoo.com so I receive an email with the body of that email consisting of the four text inputs in the right order:

Input1
Input2
Input3
Input4

On my web server, I have a php script at www.karazoo.com/sendmail.php with the following content:

<?php

$mail_to = $_REQUEST['mail_to'];
$subject = $_REQUEST['subject'];
$message = $_REQUEST['message'];
$mail_from = $_REQUEST['mail_from'];
$reply_to = $_REQUEST['reply_to'];

$headers = "From: $mail_from\r\n";
$headers .= "Reply-To: $reply_to\r\n";
$headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";
$headers .= "Content-Transfer-Encoding: 7bit\r\n";

mail(
$mail_to,
$subject,
$message,
$headers
);

?>

However, as I am a novice, I have gone as far as I can, drawing from examples and forum posts and am stuck with knowing what code to put on the On Click event of the button on Page 5 to cause me to get the email.

I am also not quite sure that the php script is totally right.

The application is to have about 60 pages with inputs, so I have deliberately included the two pages in the example so I can see how you do it. Then I can add pages and inputs without needing further help.

I think, and hope, that this may be a really good example to post in the examples forum if we could get it to work, because it would be a standard muti-form survey type application.

But maybe I am just assuaging my guilt at needing to publish such a long and demanding post.

stickck
02-11-2006, 08:52 AM
i dont know anything about PHP but after reading Corey's post on the emailer, i think i figured it out for you. this should atleast get you started. i tested it, so you may have an email sent from me. check out the sample.

i made each input into a string and then CONCAT them all together into 1 string. i also updated your HTTP.Submit script.

also, when you post a sample, use the file--export option in AMS. you just pasted the AM6 file so none of the files were uploaded with it so i had to put in the button files, backgrounds, audio..... just a pointer.:cool

chris

travisperkins
02-11-2006, 10:44 AM
Firstly, this is a really generous reply and I want to express my thanks.

It works int he basic sense, so I I could experiment to get the details right, but I thought it would be worth presenting them to you because you'll obviously know straight up how to rectify them. I hope that this doesn't make it seem like I am pushing the envelope. Also, I had not realized about the file export method. Thanks for that.

I have not re-uploaded your example because I have not made any changes to it yet.

1. After Clicking the 'Next Page' label on Page 4, in order to go to Page 5 that contains the Submit button to which the On Click Event that submits the data to the web mail script is attached, I get a Windows dialogue/Pop Up box that says 'Answers' in the top bar, and then has exactly the same as the email body in the main message area. That is:
______________
paul 1
paul 2,

paul 3,paul 4,
______________

I can not see where this is coming from, but I need to get rid of that pop up because the answers, in reality, when the application is complete, will be thousands of words drawn from many inputs. I just need that Next Page button to take the user to Page 5 where they can press the 'Submit' button.
Could you remove whatever is calling up that Pop Up?

2. As you can see above, the email I receive has the data from the first 2 inputs formatted nicely, one above the other. But, the data from Input2 and Input3 are placed next to each other seperated by a comma. What is it that you have configured to cause the Input3 and Input4 data to occupy the same line? I would like to change that so that data from each Input is given its own line and seperated, just like Input1 and Input2.

3. Finally, currently, the email I receive has a Suject of 'Answers' and has a 'Sender Unspecified' as the 'From' field. Is this something we can control from AM6, or is this something I need to sort out on the PHP side of things? If the former, could you show me which parts of your AM6 code should be amended to be able to control the Subject and the 'From' field.

Once these things are right, I will study your code carefully and, using a copy of the project, I will try and add further pages and inputs, duplicating and amending your code as necessary, to make sure I understand how the aggregation works. It looks pretty clear to me, but I did not want to do that until we have a perfect working copy of your example.

I am hoping this will be useful to others as an example too.

Again, many thanks for this care and detail. The above is long in the hope it will be clear enough to make any further input expedient.

yosik
02-11-2006, 04:51 PM
Why The Double Posts???

stickck
02-11-2006, 08:35 PM
on the UPDATE buttons in the project you will see the following scripts...
sText = Input.GetText("Input1")
TextFile.WriteFromString("Autoplay\\Docs\\InputText1.txt", sText .."\n", false)

right after the sText you will see .."\n" that is what will affect the way the data is seen. \n stands for New Line (as in the first two lines that you said you liked. the other two lines i just put ..","
and that just puts a comma between each input. check out the scripts under the update button.

as for the subject, just put in some script to open this... Subj = Dialog.Input("your title here", "Subject", "", MB_ICONQUESTION) to ask what the subject is and send that as a string like the others you already get. same goes for sender.

let me know if you need some other help, like i said, i dont know anything about PHP but should be able to figure it out.

chris

stickck
02-12-2006, 12:56 AM
Finally, currently, the email I receive has a Suject of 'Answers' and has a 'Sender Unspecified' as the 'From' field. Is this something we can control from AM6, or is this something I need to sort out on the PHP side of things? If the former, could you show me which parts of your AM6 code should be amended to be able to control the Subject and the 'From' field.

To fix these two things, you said your PHP setup has these..<?php

$mail_to = $_REQUEST['mail_to'];
$subject = $_REQUEST['subject'];
$message = $_REQUEST['message'];
$mail_from = $_REQUEST['mail_from']; -- Add this option to your mail()
$reply_to = $_REQUEST['reply_to'];

$headers = "From: $mail_from\r\n";
$headers .= "Reply-To: $reply_to\r\n";
$headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";
$headers .= "Content-Transfer-Encoding: 7bit\r\n";

mail(
$mail_to,
$subject,
$message,
$headers -- Add the line from above into here. $mail_from
);

?> In the area of mail() I would add $mail_from, that way you will know who it's from. I'm just guessing here but thats the way I understand how it should work.

Once you update your PHP scripts on your server, Then in AMS you would just update it to say something like this...

I would have a input dialog popup and ask them for their name... like this...
name = Dialog.Input("Please enter your name", "First & Last Name", "", MB_ICONQUESTION)

You could use this if you want the user to set the subject. (I personally wouldnt do it that way. I would hard code it into the global)
Subj = Dialog.Input("your title here", "Subject", "", MB_ICONQUESTION) This is how I would do it Subj = "Site Feedback";--Put whatever subject you would like in there

Then under your Submit button, you would change it so it looks like this.

sent = HTTP.Submit("http://www.karazoo.com/sendmail.php", {mail_to="biz@karazoo.com", subject=Subj, message=result, mail_from=name, headers="Whatever"}, SUBMITWEB_POST, 20, 80, nil, nil);


Am I right so far Corey? Like I said, I dont know how PHP works nor do I know how to script in PHP. I just read over the sample "Emailer".

hope this helps.

chris

Corey
02-12-2006, 01:11 AM
The AMS part looks good at a glance. As for the PHP, the mail function has only three mandatory parameters I think, the additional header info such as "from", etc. is optional as far as I remember. Seems to me you only need a "to" address, the subject and the message. So the "right" implementation will vary depending on what data you want to collect, and how you wish to collect it.

Additionally you might want to append certain data to the email "message" variable using PHP such as the sender's IP, a datestamp, etc.

But for the most part it looks good Chris, of course the only way to tell is test it. But anyhow just FYI PHP is simple beans for a guy like you and *super* powerful. I can't overemphasize how much I recommend learning a little PHP. I don't usually evangelize anything to the extent that I do PHP, it's an absolute home run IMO. I couldn't live without it. Period. I'm no PHP guru either, I'm just like the millions of others who learned enough to do what needs to be done. PHP is perfect for that. It's easy to learn as you go and man oh man does PHP ever unlock a zillion powerful features for your web sites and web apps. :yes

stickck
02-12-2006, 02:11 AM
I'll eventually take the time to learn some other scripting languages.

thanks Corey:D

Chris

Intrigued
02-12-2006, 10:27 AM
I'll eventually take the time to learn some other scripting languages.

thanks Corey:D

Chris

I need to pull out my PHP 5 book again. Don't use it, you loose... well you know. And it's not like I even knew half of all of the functions in PHP 5 when I was goofing around with it last year.

Corey
02-12-2006, 01:25 PM
My approach to PHP, actionscript, etc has always been not to try and retain stuff I don't use. I find it's actually more productive to just forget all that stuff when it's not needed. In my job sometimes I don't use any advanced PHP for months. It would be a waste of ebergy to try and retain all the syntax for tons of functions. The best approach is just to get familiar enough with the methods so that you can easily look up and implement functions when needed IMO. Sounds odd but I find sometimes the less you try to retain, them ore you get done in the long run. Low drag - high speed. :D

It's kind of like the law of diminishing returns in a way. For example I find that if I work 8 hours, then go skating for two, and then come back and work 4 more hours, I always get *way* more done than if I just try to work 12 hours in one stretch. :)

travisperkins
02-12-2006, 05:22 PM
Everything here has worked perfectly. I have not changed, because so far I have not needed to change, any of the php script. Just the changes to the AM6 code as provided here have answered all the issues.

The only thing I have noticed, of course, is that there is nothing in the email I receive to show which Input the data belongs to, and therefore, no way of seeing if a user has omitted to complete a certain input.

In other words, the email I receive is of the following order:

bla bla fron input1
bla bla from input2
bla bla from input3
bla bla from input4

But, what I would really need, and what anyone else using this would presumably want is an email of the order:

Input1: bla bla fron input1
Input2: bla bla fron input2
Input3: bla bla fron input3
Input4: bla bla fron input4

Then, the inputs could be given meaningful names such as 'Name', 'Date of Birth', 'Favorite Developer Application'.

Then if they ommited to fill in the last one, we would get an email of the order:

Name: Albert Fish
Date of Birth: March 1st 1960
Favorite Developer Application:

Without the listing of the Input filed names, the email would not obviously show that the last field was empty because there would just be nothing on that line.

To finish this application example, could someone indicate how to add this feature.

Could you also let me know where to submit examples so I can make this available to others.

Many thanks.

stickck
02-12-2006, 09:08 PM
look at post 5 in this thread.

i put in there the Concat for new line .."\n".

just add in the other info you need. ie...

under each update button change it to something like this..

TextFile.WriteFromString("Autoplay\\Docs\\InputText1.txt", "Name: ".. sText .."\n", false) your email will now look the way you asked.

change each update button to that (make sure you change the input name which i made in red above) and it you should be good. make sure you keep the input name wrapped in "" or else AMS will be looking for a variable and not just putting in the text you typed in.

chris

stickck
02-12-2006, 09:24 PM
I need to pull out my PHP 5 book again. Don't use it, you loose... well you know. And it's not like I even knew half of all of the functions in PHP 5 when I was goofing around with it last year.

Hey Intrigued,
Did you ever make any headway with LUACOM and Excel using that book? I didnt. I gave up on it. I figured that if it that difficult to configure it, it would probably be a nightmare to support the final project.

Chris

travisperkins
02-13-2006, 09:44 AM
Hi Chris

You are right, your method does exactly what I asked for.

The only trouble is that, the actual name of the Input, that replaces your "name", appears in the Input Text field itself, followed by a little square:

Name1: []

I suppose we could live with this, but it is a bit odd.

Even if I manually dlete all text from the relevant AutoPlay/Docs/***.txt, they reappear, presumably because the Inputfields are drawing the text from the code.

Can we stop it doing that?

Thanks


Travis