The Student Room Group

Need help creating a web app for pre filling an email

Hello TSR nerd corner!!(no offence meant- I aspire to be a nerd tbh)
I'm currently studying Web design outside of my usual non-ICT studies. I am getting kind of bored with the simplicity of of HTML and need to take a break from it and I have a small project I've been meaning to undertake some thought I may as well try to tackle both problems at once. Also, I'll probably learn a fair bit along the way.
Rather than being vague and explaining roughly what I want to do, I'll just go ahead and say what I want to achieve.
My friend is on a ton of medication right now and her health centre has recently joined the 21st century by offering repeat prescription requests by email!! Woooo!
I want to make her a personalised web app which would be something like this example:

Paracetamol <input type="checkbox">
Ventolin <input type="checkbox">
loads <input type="checkbox">
of <input type="checkbox">
other <input type="checkbox">
Nasty (but sadly necessary) chemicals <input type="checkbox">

My friend would just tick what she wants but when she hits send, it goes ahead and sends a prefilled email through her gmail account with a load of static information (like address, date of birth etc.)
example of sent email:

to: [email protected]
subject: repeat request

Name: Jane Doe
Date of birth: 25/12/1990
Address: 99 Some Place, London, E20
Patient Number: 37718927
<this is where the information for the checkboxes go>
Please send this prescription to the local pharmacy

sincerely

Jane Does



(that's not her real name, btw. :tongue: )

Once that is all set up, I'd make sure the page was public, but unlisted on search then I'd endeavour to optimise for iPhone. I'm hoping to do the whole lot in Google Sites if they still let you make your page unlisted. If Google Plus is anything to go by, I'd guess they'd want to make sure the whole knows exactly who made the site and OH! Here a picture of his dog, too!!... But I'll cross that bridge once I've actually made the page.

Now, I'll say up front that I'm complete noob to doing something on this level but I am doing this as a way to learn as I go. Can anyone please give me a push in the right direction to get me started?

many thanks
Original post by El_Panda
Hello TSR nerd corner!!(no offence meant- I aspire to be a nerd tbh)
I'm currently studying Web design outside of my usual non-ICT studies. I am getting kind of bored with the simplicity of of HTML and need to take a break from it and I have a small project I've been meaning to undertake some thought I may as well try to tackle both problems at once. Also, I'll probably learn a fair bit along the way.
Rather than being vague and explaining roughly what I want to do, I'll just go ahead and say what I want to achieve.
My friend is on a ton of medication right now and her health centre has recently joined the 21st century by offering repeat prescription requests by email!! Woooo!
I want to make her a personalised web app which would be something like this example:

Paracetamol <input type="checkbox">
Ventolin <input type="checkbox">
loads <input type="checkbox">
of <input type="checkbox">
other <input type="checkbox">
Nasty (but sadly necessary) chemicals <input type="checkbox">

My friend would just tick what she wants but when she hits send, it goes ahead and sends a prefilled email through her gmail account with a load of static information (like address, date of birth etc.)
example of sent email:

to: [email protected]
subject: repeat request

Name: Jane Doe
Date of birth: 25/12/1990
Address: 99 Some Place, London, E20
Patient Number: 37718927
<this is where the information for the checkboxes go>
Please send this prescription to the local pharmacy

sincerely

Jane Does



(that's not her real name, btw. :tongue: )

Once that is all set up, I'd make sure the page was public, but unlisted on search then I'd endeavour to optimise for iPhone. I'm hoping to do the whole lot in Google Sites if they still let you make your page unlisted. If Google Plus is anything to go by, I'd guess they'd want to make sure the whole knows exactly who made the site and OH! Here a picture of his dog, too!!... But I'll cross that bridge once I've actually made the page.

Now, I'll say up front that I'm complete noob to doing something on this level but I am doing this as a way to learn as I go. Can anyone please give me a push in the right direction to get me started?

many thanks


I am not familiar with Google sites, but I have a bit of web development experience.

Since you're familiar with HTML I won't talk you through how to make the physical form itself - but feel free to ask if this is difficult.

I don't know if you have any Javascript experience, but I think that would be the easiest way to send the email. The compromise is that instead of sending the email directly, it will pop up her gmail account with the message pre-written, ready for her to click 'Send'. Ideally we would use a server side language like PHP instead of a client side language like Javascript, enabling us to send the message directly, but setting up a serverside language can be difficult for a beginner, and I don't even think it's possible in Google Sites.

Assuming you have the form already written, you then need to write two Javascript functions - one to build up the body of the message, and one to send the email via gmail. I suggest you read very briefly about javascript before trying the ideas in the rest of this message, although I've tried to make things easy.

To build up the body of the message, you will need to get the relevant information from the form, and create a text string containing the desired message.
To check the contents of a checkbox, you need first to include an 'id' tag in each checkbox so we can refer to it in code, for example
Paracetamol: <input type='checkbox' id='paracetamol_checkbox'>
Then your javascript function can check the value of the checkbox and act upon it:

// Simple example of how buildMessageBody might work:
function buildMessageBody() {
var message = 'Name: Jane Doe\n'; // \n means 'newline'
message += 'Date of birth: 25/12/1990\n';
message += 'Address: 99 Some Place, London, E20\n';
message += 'Patient Number: 37718927\n\n';
message += 'Prescriptions renewals requested:'

var paracetamol_checkbox = document.getElementById('paracetamol_checkbox');
if (paracetamol_checkbox.checked) {
message += 'Paracetamol 20 x 500 mg\n';
}
// Repeat this block for all your other drugs.

message += '\nPlease send this prescription to the local pharmacy.\n\n';
message += 'Sincerely,\nJane Doe';

return message;
}


That hopefully makes it clear how to build up the contents of the email. In order to actually send the mail, copy-paste the sendGmail function from the bottom of the page at this link into your Javascript, changing the details of the email account . Then, your sendPrescriptionEmail function can look as follows:


function sendPrescriptionEmail() {
sendGmail({
to: '[email protected]',
subject: 'Repeat Prescription Request',
message: buildMessageBody()
});
}


Finally, you only need to add a 'Send Email' button to your form:

<input type='button' value='Send Email!' onClick='sendPrescriptionEmail()' />


That should do the trick. Reply, PM me, or email whiteandnerdy1729 <<at>> googlemail.com if you need more help. Hope she appreciates it!

(Disclaimer: I wrote all this code straight into the Reply box here, and haven't tested any of it. Doubtless I will have made syntax errors :tongue: )
(Disclaimer 2: I've done this the easy-to-explain way rather than the cleanest-solution way. Don't hate on my code style :smile: )
(edited 10 years ago)

Quick Reply

Latest

Trending

Trending