Jump to content

Help with a simple form


PeteMcC
Go to solution Solved by mac_gyver,

Recommended Posts

Hoping some of you guys can help me, I'm not overly familiar with coding and such but I've been asked to design a website for a friend, I'm using Dreamweaver CS4 and I need a form with three text fields and two check boxes. I've managed to find an online resource that allows you to create your own form in HTML with a php command script to email it to me, but only with text fields. When I've tried to insert check boxes in the HTML and alter the php it just messes everything up and the script doesn't work. does anyone know an easy way to create a form in HTML and a command script in php which will send it to an email address without redirecting the visitor to their email package? I've attached a screen shot of the form I've created and the feedback.php file that I got from the free site.

Basically I want to know what I need to do to that php file to make it work, or will it ever work? do I need to go down another route to get this to happen. I must have lost two days to this and anyone I've spoken to who would know assures me that it should be straightforward but 'doesn't have time to look at it'.. any help gratefully received!

Screenshot2013-07-20at093513.pngfeedback.php

Link to comment
Share on other sites

  • Solution

whatever name you gave each check-box form field will be set when the check-box is checked and won't be set if it is not checked. you would then probably want to have a conditionally statement to produce a yes/no indication to insert into your email message for each check-box.

 

php has an instruction to test if a variable is set, surprisingly its called - isset()

$ck1 = 'no'; // default to no/not checked
if(isset($_POST['your_check_box_name_1'])){
    $ck1 = 'yes';
}
$ck2 = 'no'; // default to no/not checked
if(isset($_POST['your_check_box_name_2'])){
    $ck2 = 'yes';
}
// then just include the $ck1,$ck2 strings when building your email message
    "some legend for check-box 1: $ck1" . $content_nl .
    "some legend for check-box 2: $ck2" . $content_nl .
Link to comment
Share on other sites

Thanks for the reply, I've been looking at stuff like this before, but when I try and place any of it into the php code I already have it causes it to fail ad not send a mail, can you tell me where I need to place what? Apologies if this sounds dumb as I'm a total noob to this sort of thing.

Link to comment
Share on other sites

Have you considered using a third-party alternative? Google forms, for example, are free and can be embedded within an existing website.

https://support.google.com/drive/answer/87809?hl=en

 

JotForm is another nice option. They have a free service plan and can be embedded.

http://www.jotform.com/

 

 

If you still want to build your own form (or download one from the Web), be mindful that there are risks. For example, online forms will likely be targeted for injection attacks. If you're interested, there are many tips online for avoiding e-mail injection:

https://www.google.com/search?q=email+injection+php

 

Note that I didn't download your code, so perhaps this is already taken care of.

Link to comment
Share on other sites

 

whatever name you gave each check-box form field will be set when the check-box is checked and won't be set if it is not checked. you would then probably want to have a conditionally statement to produce a yes/no indication to insert into your email message for each check-box.

 

php has an instruction to test if a variable is set, surprisingly its called - isset()

$ck1 = 'no'; // default to no/not checked
if(isset($_POST['your_check_box_name_1'])){
    $ck1 = 'yes';
}
$ck2 = 'no'; // default to no/not checked
if(isset($_POST['your_check_box_name_2'])){
    $ck2 = 'yes';
}
// then just include the $ck1,$ck2 strings when building your email message
    "some legend for check-box 1: $ck1" . $content_nl .
    "some legend for check-box 2: $ck2" . $content_nl .

afraid not. if you are not at the point that you will even make an attempt, you are not yet ready to leave the temple, grasshopper...

Fair enough! I was just trying to save myself a bit more head melting! (I'm a graphic designer, not a web guy) I was just about to post you a message, I figured it out anyway, so I really appreciate what you've done, thank you so much. It works! I'm a happy man! You're a saint :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.