PDA

View Full Version : Dreamweaver Form, PHP


Excursion
12-04-2008, 09:10 PM
Goodmorning,

I have been all over the web looking for an answer for my question and no-one seems to be able to give me a direct answer.

I have a form I want to place on my website,

HTML CODE:

<form action="/test/contact_form.php" method="post" enctype="multipart/form-data">
<!--webbot bot="SaveResults" u-file="fpweb:///_private/form_results.csv" s-format="TEXT/CSV" s-label-fields="TRUE" -->
<p class="style1">
<br>
<b>Your name:</b><br>
<input type="text" name="T1" size="32"><br>
<br>
<b>Email address:<br>
</b><input type="text" name="T2" size="32"><br>
<br>
<b>Messages:<br>
<b>
<textarea rows="10" name="S1" cols="30"></textarea>
</b></b><br>
<br>
<input type="submit" value="Submit" name="B1">
<input type="reset" value="Clear" name="B2"></p>
</form>

This links to the PHP instructions,

PHP CODE:

<?php
//--------------------------Set these paramaters--------------------------

// Subject of email sent to you.
$subject = 'Contact form';

// Your email address. This is where the form information will be sent.
$emailadd = 'excursion@hotmail.com';

// Where to redirect after form is processed.
$url = '/local_root/test/index.htm';

// Makes all fields required. If set to '1' no field can not be empty. If set to '0' any or all fields can be empty.
$req = '0';

// --------------------------Do not edit below this line--------------------------
$text = "Results from form:\n\n";
$space = ' ';
$line = '
';
foreach ($_POST as $key => $value)
{
if ($req == '1')
{
if ($value == '')
{echo "$key is empty";die;}
}
$j = strlen($key);
if ($j >= 20)
{echo "Name of form element $key cannot be longer than 20 characters";die;}
$j = 20 - $j;
for ($i = 1; $i <= $j; $i++)
{$space .= ' ';}
$value = str_replace('\n', "$line", $value);
$conc = "{$key}:$space{$value}$line";
$text .= $conc;
$space = ' ';
}
mail($emailadd, $subject, $text, 'From: '.$emailadd.'');
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
?>


I also set the HTML form properties to go to the PHP,

Action: /test/contact_form.php

When I click on the submit button the form just sits there, like the button is broken.

I have tried a varity of different form templates and been to over 5 different sites. With very little progress.

Do I need to upload the site to a webhost before testing???

Please someone tell my what is going wrong!

edbr
12-05-2008, 12:06 AM
if you want the mail sent it must be on a webserver that supports php.
the form when submitted should bring you to the action page though you have reset the redirect to /local_root/test/index.htm';
i would comment this out then see what happens this is an unusual path.

also not sure what this is
<!--webbot bot="SaveResults" u-file="fpweb:///_private/form_results.csv" s-format="TEXT/CSV" s-label-fields="TRUE" -->

Excursion
12-05-2008, 12:30 AM
I am mostly self taught so I have alot of holes in my knowledge base, This simple comment has been one of the most difficult answers to get someone to give me!

if you want the mail sent it must be on a webserver that supports php.

Thank you...

So is there anyway I can trick my computer into becoming a web server for testing purposes? I tried downloading WampServer but have not really tried it out yet, can it create a virtual server on my computer?

Regarding the code,
It was located in the tutorials section of this website, I used it because it appeared to be the most simple out of all the codes ive seen on the web so far.

I understand what it has explained in regards to the pathways and names of things,

Could you repost my code with what you would consider a correct way of doing it. Until I see a working/tested code I have no clue if im going in the correct direction.

I can use my old webhost to test the code and such.

It has been over 5 days looking into this one "apparently simple" piece of code.

Many thanks for your response, I hope you can help further

edbr
12-05-2008, 02:22 AM
no it wont work locally , upload it live and try it.
for the rest it looks as if it should work to me, qne word of warning is re validation any email script should be validated to make sure (for one thing) spammers cant use your form for spamming .

as to the code for testing purposes try this , (with the redirect commented out)
<?php
//--------------------------Set these paramaters--------------------------

// Subject of email sent to you.
$subject = 'Contact form';

// Your email address. This is where the form information will be sent.
$emailadd = 'excursion@hotmail.com';

// Where to redirect after form is processed.
// $url = '/local_root/test/index.htm';

// Makes all fields required. If set to '1' no field can not be empty. If set to '0' any or all fields can be empty.
$req = '0';

// --------------------------Do not edit below this line--------------------------
$text = "Results from form:\n\n";
$space = ' ';
$line = '
';
foreach ($_POST as $key => $value)
{
if ($req == '1')
{
if ($value == '')
{echo "$key is empty";die;}
}
$j = strlen($key);
if ($j >= 20)
{echo "Name of form element $key cannot be longer than 20 characters";die;}
$j = 20 - $j;
for ($i = 1; $i <= $j; $i++)
{$space .= ' ';}
$value = str_replace('\n', "$line", $value);
$conc = "{$key}:$space{$value}$line";
$text .= $conc;
$space = ' ';
}
mail($emailadd, $subject, $text, 'From: '.$emailadd.'');
// echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
?>