Free Blog |  HTTPPoint discussion forum |  Recreation vehicle insurance |  Casino news |  Debt Info |  Debt Info(uk) |  Computer Info |  History of computer |  Flight Simulator | 

PDA

View Full Version : Here is the code


John
06-13-2008, 20:55
<form
class="cssform" action="">
<p>
<label for="user">Name:</label>
<input type="text" id="user" value="" />
</p>
<p>
<label for="emailaddress">Email Address:</label>
<input type="text" id="emailaddress" value="" />
</p>
<p>
<label for="phone">Phone Number:</label>
<input type="text" id="phone" value="" />
</p>
<p>
<label for="call">Best Time To Call:</label>
Morning:
<input type="radio" name="call" />
Afternoon:
<input type="radio" name="call" />
Night
<input type="radio" name="call" />
</p>
<p><label for="call">Subject:</label>
<select name="web">
<option selected value="">Quote</option>
<option value="">Tech Support</option>
</option>
</select>
<br><br><br>
<p><label for="comments">Comments:</label>
<textarea name="comments" rows="" cols=""></textarea>


<div style="margin-left: 150px;">
<input type="submit" value="Submit" />
<input type="reset" value="Reset" />
</div>
</form>
</div>
<div id="right">
<h2>Search our site</h2>
<form action="#" method="get" style="margin-top: 0; margin-bottom:
0;">
<p>
<input type="text" name="q" size="25" maxlength="255" value=""
class="search"/>
<input type="submit" name="search" value="Search"
class="search" />
</p>

</form>

Lammi
06-13-2008, 20:55
i assume you wanna get the form via email? thescript below will give
you a text-formatted email, listing all fields and the given values.

<?php

if (isset($_POST['Send']))


$to = 'you@email.com';
$subject = 'Request from Website';

$myEmail = "A new request was sent:\n";
foreach ($_POST as $key => $value)
$myEmail .= $key.". ".$value."\n";

mail ($to, $subject, $myEmail);
?>

<form class="cssform" action="<? $_SERVER['PHP_SELF'] ?>">
<p>
<label for="user">Name:</label>
<input type="text" name="user" id="user" value="" />
</p>
<p>
<label for="emailaddress">Email Address:</label>
<input type="text" name="emailadress" id="emailaddress"
value="" />
</p>
<p>
<label for="phone">Phone Number:</label>
<input type="text" name="phone" id="phone" value="" />
</p>
<p>
<label for="call">Best Time To Call:</label>
Morning:
<input type="radio" name="call" />
Afternoon:
<input type="radio" name="call" />
Night
<input type="radio" name="call" />
</p>
<p><label for="call">Subject:</label>
<select name="web">
<option selected value="Quote">Quote</option>
<option value="Tech Support">Tech Support</option>
</option>
</select>
<br><br><br>
<p><label for="comments">Comments:</label>
<textarea name="comments" rows="" cols=""></textarea>

<div style="margin-left: 150px;">
<input type="submit" value="Submit" name="Send" />
<input type="reset" value="Reset" name="Reset" />
</div>

do some</form>

Robin
06-13-2008, 20:55
Lammi wrote:
> i assume you wanna get the form via email? thescript below will give
> you a text-formatted email, listing all fields and the given values.
>
> <?php
>
> if (isset($_POST['Send']))
>
>
> $to = 'you@email.com';
> $subject = 'Request from Website';
>
> $myEmail = "A new request was sent:\n";
> foreach ($_POST as $key => $value)
> $myEmail .= $key.". ".$value."\n";
>
> mail ($to, $subject, $myEmail);
> ?>
>
> <form class="cssform" action="<? $_SERVER['PHP_SELF'] ?>">
> <p>
> <label for="user">Name:</label>
> <input type="text" name="user" id="user" value="" />
> </p>
> <p>
> <label for="emailaddress">Email Address:</label>
> <input type="text" name="emailadress" id="emailaddress"
> value="" />
> </p>
> <p>
> <label for="phone">Phone Number:</label>
> <input type="text" name="phone" id="phone" value="" />
> </p>
> <p>
> <label for="call">Best Time To Call:</label>
> Morning:
> <input type="radio" name="call" />
> Afternoon:
> <input type="radio" name="call" />
> Night
> <input type="radio" name="call" />
> </p>
> <p><label for="call">Subject:</label>
> <select name="web">
> <option selected value="Quote">Quote</option>
> <option value="Tech Support">Tech Support</option>
> </option>
> </select>
> <br><br><br>
> <p><label for="comments">Comments:</label>
> <textarea name="comments" rows="" cols=""></textarea>
>
> <div style="margin-left: 150px;">
> <input type="submit" value="Submit" name="Send" />
> <input type="reset" value="Reset" name="Reset" />
> </div>
>
> do some</form>
>

You will need a { after the if and a } after the mail().

I would do some validation of the POST data before sending possibly
malicious data to myself.

Note that Lammi added name="xxx" to the input tags (you cannot use just
id="xxx" they aren't the same thing).

Also, he added a value for the action attribute of the form, though
using $_SERVER['PHP_SELF'] is no longer considered a good idea due to
XSS exploits.

Lammi
06-13-2008, 20:55
> You will need a { after the if and a } after the mail().

of course he need, my fault. sorry.

> I would do some validation of the POST data before sending possibly
> malicious data to myself.

i would do such validation too - but john asked only for a way to
transfer the data :-)

> Also, he added a value for the action attribute of the form, though
> using $_SERVER['PHP_SELF'] is no longer considered a good idea due to
> XSS exploits.

i wouldn't realize the validation, emailing and form in one single
page, i would create a simple html-file containing the form and
nothing else, a small validation-class and a class to create the
email. it's never a good idea to mix html- and php-code i think.

John
06-13-2008, 20:55
>>> I would do some validation of the POST data before sending possibly
malicious data to myself.



Can you write out how I would do validation in the code?


Thanks for all of the help so far.




Also I tried this and named it mail.php:


<?php

if (isset($_POST['Send']))
{

$to = 'primster7@gmail.com';
$subject = 'Request from Website';

$myEmail = "A new request was sent:\n";
foreach ($_POST as $key => $value)
$myEmail .= $key.". ".$value."\n";

mail ($to, $subject, $myEmail);
}
?>


with the } line but it didn't send me the email.



I have this for the form:



<form
class="cssform" action="mail.php" method="post">
<p>
<label for="user">Name:</label>
<input type="text" id="user" value="" />
</p>
<p>
<label for="emailaddress">Email Address:</label>
<input type="text" id="emailaddress" value="" />
</p>
<p>
<label for="phone">Phone Number:</label>
<input type="text" id="phone" value="" />
</p>
<p>
<label for="call">Best Time To Call:</label>
Morning:
<input type="radio" name="call" />
Afternoon:
<input type="radio" name="call" />
Night
<input type="radio" name="call" />
</p>
<p><label for="call">Subject:</label>
<select name="web">
<option value="">Website Quote</option>
<option selected value="">Tech Support</option>
</option>
</select>
<br><br><br>
<p><label for="comments">Comments:</label>
<textarea name="comments" rows="" cols=""></textarea>


<div style="margin-left: 150px;">
<input type="submit" value="Submit" />
<input type="reset" value="Reset" />
</div>
</form>

Lammi
06-13-2008, 20:55
you need to add a "name='xxxxx'" to every form-field, as i did in my
example.
does the script run on windows or *nix? if on windows, you need to
add the mailserver-information to php.ini.

to validate the form-data you've only to do things like strip_tags,
addslashes, check for forbidden signs.

Free Blog |  HTTPPoint discussion forum |  Recreation vehicle insurance |  Casino news |  Debt Info |  Debt Info(uk) |  Computer Info |  History of computer |  Flight Simulator | 
Debt Management
Debt management information and advice from Kensington Finance.

Ethernet articles
Web Articles directory is a free article submission service, containing information on general issues.