Forums
This topic is locked
Forms in Dreamweaver
Replies
Replied 24 Jun 2005 00:28:36
24 Jun 2005 00:28:36 Dave Thomas replied:
that all depends on what u want the form to actually do when u submit it.
a bit of clarification on the form's purpose would help
regards
Dave Thomas
<b>DMX Zone Manager</b>
a bit of clarification on the form's purpose would help
regards
Dave Thomas
<b>DMX Zone Manager</b>
Replied 25 Jun 2005 03:19:29
25 Jun 2005 03:19:29 c cc replied:
well basically the form will consist of putting your name, address, and comment. I've made up the fields for those contents to be put in and i put in a submit button. Is there anything else i need for the form to work? I read somewhere i would need a form handler or something like that in order for the form to work?
Replied 26 Jun 2005 05:26:54
26 Jun 2005 05:26:54 Nikkisha Barnard replied:
You still need to clarify what you want the form to do i.e. have the information emailed to you, go to another page etc. That is what the form object will do it will tell your HTML to go and do some action.
NB
#1 Player
NB
#1 Player
Replied 11 Oct 2007 04:56:37
11 Oct 2007 04:56:37 Lawrence Pillay replied:
Hey wow, I need help with the same thing. I've created the entire design of the form in dreamweaver. I want ppl to be able to click on the submit button and the info get sent to a php file which will then send it to an email.
I have no idea what code I need to put in the dreamweaver file and how to make a php file. I know for php, all I would have to do is save the file with the extension .php in dreamweaver but what codes do I need to put in?
This is what the form is set up as:
Full name:
Contact Phone Number:
Suburb Currently Living In:
State: (This is a drop down button which is set to NSW by default)
Postcode:
Deposit amount you currently have to put towards your own home:
Current Weekly Rent:
Current Net Income:
Is Your Credit Rating:
How did you hear about us? :
Comments:
(Submit Application) - this is the submit button.
Help will be much appreciated... I urgently need to finish this site <img src=../images/fwzone/forum/icon_smile_sad.gif border=0 align=middle>
I have no idea what code I need to put in the dreamweaver file and how to make a php file. I know for php, all I would have to do is save the file with the extension .php in dreamweaver but what codes do I need to put in?
This is what the form is set up as:
Full name:
Contact Phone Number:
Suburb Currently Living In:
State: (This is a drop down button which is set to NSW by default)
Postcode:
Deposit amount you currently have to put towards your own home:
Current Weekly Rent:
Current Net Income:
Is Your Credit Rating:
How did you hear about us? :
Comments:
(Submit Application) - this is the submit button.
Help will be much appreciated... I urgently need to finish this site <img src=../images/fwzone/forum/icon_smile_sad.gif border=0 align=middle>
Replied 15 Oct 2007 13:22:53
15 Oct 2007 13:22:53 Alan C replied:
when your users click the submit button all the form fields go back to the server where they can be accessed in either the GET or POST arrays, depending on which method you selected in your form.
The hard bit IMHO is first deciding just what you want to happen, and then sorting out the validation of the information that was in the form fields. As the man said clarify what you want to happen.
Once you know that you can decide what to do with the data - bear in mind that there are a lot of unscrupulous people out there who will intentionally try to "break' your form but sending strange data, and there are a lot of other who will just get it wrong or forget to put the details in. Writing the code to handle these cases is much harder than the straightforward one.
Also take a look at formstogo - an application that will take your DW form and let you specify validation - takes a lot of the pain out of doing this kind of thing
The hard bit IMHO is first deciding just what you want to happen, and then sorting out the validation of the information that was in the form fields. As the man said clarify what you want to happen.
Once you know that you can decide what to do with the data - bear in mind that there are a lot of unscrupulous people out there who will intentionally try to "break' your form but sending strange data, and there are a lot of other who will just get it wrong or forget to put the details in. Writing the code to handle these cases is much harder than the straightforward one.
Also take a look at formstogo - an application that will take your DW form and let you specify validation - takes a lot of the pain out of doing this kind of thing
Replied 18 Oct 2007 06:47:33
18 Oct 2007 06:47:33 Lawrence Pillay replied:
Hey Alan C, thanks for letting me know about Formstogo. I finally got it to send info from the form to email. Its a demo version so a lot of its functions are limited.
Theres just one thing it doesnt do, which is give me an option to link my custom thank you page. Can you tell me how to do this?
I decided I'd have to change the $Success coding at the bottom of the php it created, but just dunno how.
Theres just one thing it doesnt do, which is give me an option to link my custom thank you page. Can you tell me how to do this?
I decided I'd have to change the $Success coding at the bottom of the php it created, but just dunno how.
Replied 18 Oct 2007 17:39:07
18 Oct 2007 17:39:07 Alan C replied:
Hi Lawrence,
I usually end up hacking formstogo's code too, my version of forms to go is 3 .0.4 and it's an unregistered version.
here's a real example . . .
<pre id=code><font face=courier size=2 id=code># Redirect user to the error page
if ($ValidationFailed == true) {
header("Location: fail.htm"
exit;
}
# Email to Form Owner
$emailSubject = FilterCChars("Booking form from website"
$emailBody = "The following details have been sent from the website:\n"
. "\n"
. "name : $FTGname\n"
. "email : $FTGemail\n"
. "street_address : $FTGstreet_address\n"
. "city : $FTGcity\n"
. "postcode : $FTGpostcode\n"
. "tel : $FTGtel\n"
. "arrival_date : $FTGarrival_date\n"
. "deaprt_date : $FTGdeaprt_date\n"
. "occupancy : $FTGoccupancy\n"
. "occupancy_details : $FTGoccupancy_details\n"
. "arrival_time : $FTGarrival_time\n"
. "special_requests : $FTGspecial_requests\n"
. "confirm_via : $FTGconfirm_via\n"
. "\n"
. "----------\n"
. "";
$emailTo = "email address of recipient goes here";
$emailFrom = FilterCChars("web.enquiry@yourdomain or whatever youlike "
$emailHeader = "From: $emailFrom\n"
. "MIME-Version: 1.0\n"
. "Content-type: text/plain; charset=\"ISO-8859-1\"\n"
. "Content-transfer-encoding: 8bit\n";
mail($emailTo, $emailSubject, $emailBody, $emailHeader);
# Redirect user to success page
header("Location: success.htm"
exit; </font id=code></pre id=code>
the variable $ValidationFailed gets set to true if any of the validations fail, so here it gets tested, if it's true the code redirects the user to the failure page, if it's false the email gets sent and the user is sent to the success page. It's a while since I did one of these so I can't remember whether the free version does this test for you. It's important that the script that does the test does not try to send any output back to the browser, leave that to the success or fail pages, otherwise you will get an error message something like 'headers already sent'
I usually end up hacking formstogo's code too, my version of forms to go is 3 .0.4 and it's an unregistered version.
here's a real example . . .
<pre id=code><font face=courier size=2 id=code># Redirect user to the error page
if ($ValidationFailed == true) {
header("Location: fail.htm"
exit;
}
# Email to Form Owner
$emailSubject = FilterCChars("Booking form from website"
$emailBody = "The following details have been sent from the website:\n"
. "\n"
. "name : $FTGname\n"
. "email : $FTGemail\n"
. "street_address : $FTGstreet_address\n"
. "city : $FTGcity\n"
. "postcode : $FTGpostcode\n"
. "tel : $FTGtel\n"
. "arrival_date : $FTGarrival_date\n"
. "deaprt_date : $FTGdeaprt_date\n"
. "occupancy : $FTGoccupancy\n"
. "occupancy_details : $FTGoccupancy_details\n"
. "arrival_time : $FTGarrival_time\n"
. "special_requests : $FTGspecial_requests\n"
. "confirm_via : $FTGconfirm_via\n"
. "\n"
. "----------\n"
. "";
$emailTo = "email address of recipient goes here";
$emailFrom = FilterCChars("web.enquiry@yourdomain or whatever youlike "
$emailHeader = "From: $emailFrom\n"
. "MIME-Version: 1.0\n"
. "Content-type: text/plain; charset=\"ISO-8859-1\"\n"
. "Content-transfer-encoding: 8bit\n";
mail($emailTo, $emailSubject, $emailBody, $emailHeader);
# Redirect user to success page
header("Location: success.htm"
exit; </font id=code></pre id=code>
the variable $ValidationFailed gets set to true if any of the validations fail, so here it gets tested, if it's true the code redirects the user to the failure page, if it's false the email gets sent and the user is sent to the success page. It's a while since I did one of these so I can't remember whether the free version does this test for you. It's important that the script that does the test does not try to send any output back to the browser, leave that to the success or fail pages, otherwise you will get an error message something like 'headers already sent'
Replied 19 Oct 2007 10:48:12
19 Oct 2007 10:48:12 Lawrence Pillay replied:
Thanks Alan, I'll try to match up your code to mine and try to change what needs changing. But just incase, heres what mine looks like and if you could show me where to edit:
<?PHP
######################################################
# #
# Forms To Go 3.2.5 #
# www.bebosoft.com/ #
# #
######################################################
######################################################
# #
# UNREGISTERED COPY #
# Forms To Go is shareware #
# Please register the software #
# www.bebosoft.com/ #
# #
######################################################
DEFINE('kOptional', true);
DEFINE('kMandatory', false);
DEFINE('kStringRangeFrom', 1);
DEFINE('kStringRangeTo', 2);
DEFINE('kStringRangeBetween', 3);
DEFINE('kYes', 'yes');
DEFINE('kNo', 'no');
error_reporting(E_ERROR | E_WARNING | E_PARSE);
ini_set('track_errors', true);
function DoStripSlashes($FieldValue)
{
if ( get_magic_quotes_gpc() ) {
if (is_array($FieldValue) ) {
return array_map('DoStripSlashes', $FieldValue);
} else {
return stripslashes($FieldValue);
}
} else {
return $FieldValue;
}
}
#----------
# FilterCChars:
function FilterCChars($TheString)
{
return preg_replace('/[\x00-\x1F]/', '', $TheString);
}
#----------
# Validate: String
function check_string($value, $low, $high, $mode, $limitalpha, $limitnumbers, $limitemptyspaces, $limitextrachars, $optional)
{
if ($limitalpha == kYes) {
$regexp = 'A-Za-z';
}
if ($limitnumbers == kYes) {
$regexp .= '0-9';
}
if ($limitemptyspaces == kYes) {
$regexp .= ' ';
}
if (strlen($limitextrachars) > 0) {
$search = array('\\', '[', ']', '-', '$', '.', '*', '(', ')', '?', '+', '^', '{', '}', '|');
$replace = array('\\\\', '\[', '\]', '\-', '\$', '\.', '\*', '\(', '\)', '\?', '\+', '\^', '\{', '\}', '\|');
$regexp .= str_replace($search, $replace, $limitextrachars);
}
if ( (strlen($regexp) > 0) && (strlen($value) > 0) ){
if (preg_match('/[^' . $regexp . ']/', $value)) {
return false;
}
}
if ( (strlen($value) == 0) && ($optional === kOptional) ) {
return true;
} elseif ( (strlen($value) >= $low) && ($mode == kStringRangeFrom) ) {
return true;
} elseif ( (strlen($value) <= $high) && ($mode == kStringRangeTo) ) {
return true;
} elseif ( (strlen($value) >= $low) && (strlen($value) <= $high) && ($mode == kStringRangeBetween) ) {
return true;
} else {
return false;
}
}
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ClientIP = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ClientIP = $_SERVER['REMOTE_ADDR'];
}
$FTGFullName = DoStripSlashes( $_REQUEST['FullName'] );
$FTGContactNumber = DoStripSlashes( $_REQUEST['ContactNumber'] );
$FTGSuburb = DoStripSlashes( $_REQUEST['Suburb'] );
$FTGState = DoStripSlashes( $_REQUEST['State'] );
$FTGPostcode = DoStripSlashes( $_REQUEST['Postcode'] );
$FTGselect = DoStripSlashes( $_REQUEST['select'] );
$FTGWeeklyRent = DoStripSlashes( $_REQUEST['WeeklyRent'] );
$FTGNetIncome = DoStripSlashes( $_REQUEST['NetIncome'] );
$FTGselect2 = DoStripSlashes( $_REQUEST['select2'] );
$FTGselect3 = DoStripSlashes( $_REQUEST['select3'] );
$FTGselect4 = DoStripSlashes( $_REQUEST['select4'] );
$FTGComments = DoStripSlashes( $_REQUEST['Comments'] );
$FTGbutton = DoStripSlashes( $_REQUEST['button'] );
# Fields Validations
$ValidationFailed = false;
if (!check_string($FTGFullName, 1, 0, kStringRangeFrom, kNo, kNo, kNo, '', kMandatory)) {
$ValidationFailed = true;
$FTGFullName_errmsg = 'You have to provide your name';
$ErrorList .= $FTGFullName_errmsg . '<br/>';
}
if (!check_string($FTGContactNumber, 1, 0, kStringRangeFrom, kNo, kNo, kNo, '', kMandatory)) {
$ValidationFailed = true;
$FTGContactNumber_errmsg = 'You have to provide your Phone Contact';
$ErrorList .= $FTGContactNumber_errmsg . '<br/>';
}
# Include message in error page and dump it to the browser
if ($ValidationFailed === true) {
$ErrorPage = '<html><head><title>Error</title></head><body>Errors found: <!--VALIDATIONERROR--></body></html>';
echo $ErrorPage;
exit;
}
# Email to Form Owner
$emailSubject = FilterCChars("Get A Home - Registration"
$emailBody = "FullName : $FTGFullName\n"
. "ContactNumber : $FTGContactNumber\n"
. "Suburb : $FTGSuburb\n"
. "State : $FTGState\n"
. "Postcode : $FTGPostcode\n"
. "select : $FTGselect\n"
. "WeeklyRent : $FTGWeeklyRent\n"
. "NetIncome : $FTGNetIncome\n"
. "select2 : $FTGselect2\n"
. "select3 : $FTGselect3\n"
. "select4 : $FTGselect4\n"
. "Comments : $FTGComments\n"
. "button : $FTGbutton\n"
. "";
$emailTo = ' ';
$emailFrom = FilterCChars(" "
$emailHeader = "From: $emailFrom\n"
. "MIME-Version: 1.0\n"
. "Content-type: text/plain; charset=\"ISO-8859-1\"\n"
. "Content-transfer-encoding: 8bit\n";
mail($emailTo, $emailSubject, $emailBody, $emailHeader);
# Include message in the success page and dump it to the browser
$SuccessPage = '<html><head><title>Success</title></head><body>Form submitted successfully. It will be reviewed soon.</body></html>';
echo $SuccessPage;
exit;
?>
<?PHP
######################################################
# #
# Forms To Go 3.2.5 #
# www.bebosoft.com/ #
# #
######################################################
######################################################
# #
# UNREGISTERED COPY #
# Forms To Go is shareware #
# Please register the software #
# www.bebosoft.com/ #
# #
######################################################
DEFINE('kOptional', true);
DEFINE('kMandatory', false);
DEFINE('kStringRangeFrom', 1);
DEFINE('kStringRangeTo', 2);
DEFINE('kStringRangeBetween', 3);
DEFINE('kYes', 'yes');
DEFINE('kNo', 'no');
error_reporting(E_ERROR | E_WARNING | E_PARSE);
ini_set('track_errors', true);
function DoStripSlashes($FieldValue)
{
if ( get_magic_quotes_gpc() ) {
if (is_array($FieldValue) ) {
return array_map('DoStripSlashes', $FieldValue);
} else {
return stripslashes($FieldValue);
}
} else {
return $FieldValue;
}
}
#----------
# FilterCChars:
function FilterCChars($TheString)
{
return preg_replace('/[\x00-\x1F]/', '', $TheString);
}
#----------
# Validate: String
function check_string($value, $low, $high, $mode, $limitalpha, $limitnumbers, $limitemptyspaces, $limitextrachars, $optional)
{
if ($limitalpha == kYes) {
$regexp = 'A-Za-z';
}
if ($limitnumbers == kYes) {
$regexp .= '0-9';
}
if ($limitemptyspaces == kYes) {
$regexp .= ' ';
}
if (strlen($limitextrachars) > 0) {
$search = array('\\', '[', ']', '-', '$', '.', '*', '(', ')', '?', '+', '^', '{', '}', '|');
$replace = array('\\\\', '\[', '\]', '\-', '\$', '\.', '\*', '\(', '\)', '\?', '\+', '\^', '\{', '\}', '\|');
$regexp .= str_replace($search, $replace, $limitextrachars);
}
if ( (strlen($regexp) > 0) && (strlen($value) > 0) ){
if (preg_match('/[^' . $regexp . ']/', $value)) {
return false;
}
}
if ( (strlen($value) == 0) && ($optional === kOptional) ) {
return true;
} elseif ( (strlen($value) >= $low) && ($mode == kStringRangeFrom) ) {
return true;
} elseif ( (strlen($value) <= $high) && ($mode == kStringRangeTo) ) {
return true;
} elseif ( (strlen($value) >= $low) && (strlen($value) <= $high) && ($mode == kStringRangeBetween) ) {
return true;
} else {
return false;
}
}
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ClientIP = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ClientIP = $_SERVER['REMOTE_ADDR'];
}
$FTGFullName = DoStripSlashes( $_REQUEST['FullName'] );
$FTGContactNumber = DoStripSlashes( $_REQUEST['ContactNumber'] );
$FTGSuburb = DoStripSlashes( $_REQUEST['Suburb'] );
$FTGState = DoStripSlashes( $_REQUEST['State'] );
$FTGPostcode = DoStripSlashes( $_REQUEST['Postcode'] );
$FTGselect = DoStripSlashes( $_REQUEST['select'] );
$FTGWeeklyRent = DoStripSlashes( $_REQUEST['WeeklyRent'] );
$FTGNetIncome = DoStripSlashes( $_REQUEST['NetIncome'] );
$FTGselect2 = DoStripSlashes( $_REQUEST['select2'] );
$FTGselect3 = DoStripSlashes( $_REQUEST['select3'] );
$FTGselect4 = DoStripSlashes( $_REQUEST['select4'] );
$FTGComments = DoStripSlashes( $_REQUEST['Comments'] );
$FTGbutton = DoStripSlashes( $_REQUEST['button'] );
# Fields Validations
$ValidationFailed = false;
if (!check_string($FTGFullName, 1, 0, kStringRangeFrom, kNo, kNo, kNo, '', kMandatory)) {
$ValidationFailed = true;
$FTGFullName_errmsg = 'You have to provide your name';
$ErrorList .= $FTGFullName_errmsg . '<br/>';
}
if (!check_string($FTGContactNumber, 1, 0, kStringRangeFrom, kNo, kNo, kNo, '', kMandatory)) {
$ValidationFailed = true;
$FTGContactNumber_errmsg = 'You have to provide your Phone Contact';
$ErrorList .= $FTGContactNumber_errmsg . '<br/>';
}
# Include message in error page and dump it to the browser
if ($ValidationFailed === true) {
$ErrorPage = '<html><head><title>Error</title></head><body>Errors found: <!--VALIDATIONERROR--></body></html>';
echo $ErrorPage;
exit;
}
# Email to Form Owner
$emailSubject = FilterCChars("Get A Home - Registration"
$emailBody = "FullName : $FTGFullName\n"
. "ContactNumber : $FTGContactNumber\n"
. "Suburb : $FTGSuburb\n"
. "State : $FTGState\n"
. "Postcode : $FTGPostcode\n"
. "select : $FTGselect\n"
. "WeeklyRent : $FTGWeeklyRent\n"
. "NetIncome : $FTGNetIncome\n"
. "select2 : $FTGselect2\n"
. "select3 : $FTGselect3\n"
. "select4 : $FTGselect4\n"
. "Comments : $FTGComments\n"
. "button : $FTGbutton\n"
. "";
$emailTo = ' ';
$emailFrom = FilterCChars(" "
$emailHeader = "From: $emailFrom\n"
. "MIME-Version: 1.0\n"
. "Content-type: text/plain; charset=\"ISO-8859-1\"\n"
. "Content-transfer-encoding: 8bit\n";
mail($emailTo, $emailSubject, $emailBody, $emailHeader);
# Include message in the success page and dump it to the browser
$SuccessPage = '<html><head><title>Success</title></head><body>Form submitted successfully. It will be reviewed soon.</body></html>';
echo $SuccessPage;
exit;
?>
Replied 19 Oct 2007 13:38:19
19 Oct 2007 13:38:19 Alan C replied:
OK,
let's look at that code . . .
<pre id=code><font face=courier size=2 id=code> if ($ValidationFailed === true) {
$ErrorPage = '<html><head><title>Error</title></head><body>Errors found: <!--VALIDATIONERROR--></body></html>';
echo $ErrorPage;
exit;</font id=code></pre id=code>
is the bit that generates a whole page, what it does is sends a page that just has Errors found: on it, then an html comment, not a good-looking page but at least it tells your user that something has gone wrong, if you want to use your own page here you need to make the script redirect to your page.
You can do that with a redirect like this . . .
<pre id=code><font face=courier size=2 id=code> if ($ValidationFailed == true) {
header("Location: fail.htm"
exit;
}</font id=code></pre id=code>
there is a difference in the php operators between your version and my version of ftg, mine uses == yours === there is a difference, == means equals whereas === means is exactly equal to , probably best to use ===
fail.htm is the page that will be shown, you will need to get the path right if it is not in the same directory as the script
at the bottom . . .
<pre id=code><font face=courier size=2 id=code> # Include message in the success page and dump it to the browser
$SuccessPage = '<html><head><title>Success</title></head><body>Form submitted successfully. It will be reviewed soon.</body></html>';
echo $SuccessPage;</font id=code></pre id=code>
does something similar, it generates a very short page and sends it, you could use something like this . . .
<pre id=code><font face=courier size=2 id=code>
# Redirect user to success page
header("Location: success.htm"</font id=code></pre id=code>
where success.htm is the page that will get shown - much nicer to do it like that so you can format the page exactly how you want to fit in with the rest of your site
Hope that sorts it out
let's look at that code . . .
<pre id=code><font face=courier size=2 id=code> if ($ValidationFailed === true) {
$ErrorPage = '<html><head><title>Error</title></head><body>Errors found: <!--VALIDATIONERROR--></body></html>';
echo $ErrorPage;
exit;</font id=code></pre id=code>
is the bit that generates a whole page, what it does is sends a page that just has Errors found: on it, then an html comment, not a good-looking page but at least it tells your user that something has gone wrong, if you want to use your own page here you need to make the script redirect to your page.
You can do that with a redirect like this . . .
<pre id=code><font face=courier size=2 id=code> if ($ValidationFailed == true) {
header("Location: fail.htm"
exit;
}</font id=code></pre id=code>
there is a difference in the php operators between your version and my version of ftg, mine uses == yours === there is a difference, == means equals whereas === means is exactly equal to , probably best to use ===
fail.htm is the page that will be shown, you will need to get the path right if it is not in the same directory as the script
at the bottom . . .
<pre id=code><font face=courier size=2 id=code> # Include message in the success page and dump it to the browser
$SuccessPage = '<html><head><title>Success</title></head><body>Form submitted successfully. It will be reviewed soon.</body></html>';
echo $SuccessPage;</font id=code></pre id=code>
does something similar, it generates a very short page and sends it, you could use something like this . . .
<pre id=code><font face=courier size=2 id=code>
# Redirect user to success page
header("Location: success.htm"</font id=code></pre id=code>
where success.htm is the page that will get shown - much nicer to do it like that so you can format the page exactly how you want to fit in with the rest of your site
Hope that sorts it out
Replied 20 Oct 2007 08:48:02
20 Oct 2007 08:48:02 Lawrence Pillay replied:
Thanks a lot Alan! I did the exact same thing before I even came to check your comment. Its Saturday and I go back to work on Monday, so it'll be then that I get to upload the website and see if it works. Its so weird, a week before I used to look at all that coding and it looked like gibberish to me but after you started helping, I'm starting to see whats happening. Thanks a lot Alan for taking the time to help me out . I'll let you know whether the website worked or not.