Shaunk
07-02-2009, 04:19 PM
I would appreciate any help. I am new to php and have been given a task of coming up with a form using an outside data file not MSQL but a CSV or TXT file type. I need to make the data from these files (it would be peoples names) load into the form dynamically and create checkboxes that state either they selected yes or no. Right now the TXT file has the input statue included. Can that be added dynamically to the form. So the TXT file just has names? And they get dumped into the form.
There will be multiple forms for different areas of our business so the number of names is unknown. Then I need to mail their selection off when they hit submit.
I have been able to do this manually but with some 150 forms I don't have the time to devote souly to this. Plus there has to be an easier way. Hopefully?
[CODE]
<?php
$errmsg = 'Could not send file!'; // error message
if(isset($_POST['send']))
{
$Jay=($_POST['Jay'])?"Jay Alloway: Yes":"Jay Alloway: No";
$Richard=($_POST['Richard'])?"Richard Becker: Yes":"Richard Becker: No";
$Nancy=($_POST['Nancy'])?"Nancy Becker: Yes":"Nancy Becker: No";
$Julie=($_POST['Julie'])?"Julie Bell: Yes":"Julie Bell: No";
$email = $_POST['email'];
$question = $_POST['question'];
$subject = 'Constituency Employee Verification';
$headers = "MIME-Version: 1.0\r\n";
$headers = "Content-type: text/html; charset=iso-8859-1\r\n";
$headers = "Content-Transfer-Encoding: 7bit\r\n";
$headers = "From: $email\r\n";
if(trim($email) == '')
{
$errmsg = 'Please enter your email address';
}
else if(!isEmail($email))
{
$errmsg = 'Your email address is not valid';
}
if($errmsg == '')
{
if(get_magic_quotes_gpc())
{
$question = stripslashes($question);
}
// the email will be sent here
$to = "shaunk@found.ksu.edu";
// the email subject ( modify it as you wish )
$subject = 'Results from Academic Services Technology Verification form' ;
// the mail message ( add any additional information if you want )
$msg = "$Jay \n$Richard \n$Nancy \n$Julie \n\nE-mail = $email \n\nAdditional Employees = $question \n\n " . $message;
//mail($to, $subject, $msg, "From: $from\r\nReply-To: $from\r\nReturn-Path: $from\r\n");
$mailsent = mail("$to,$email", $subject, $msg, $headers);
if (mailsent) {
echo "<h2>Thank you for filling out our Constituency Employee form!</h2>";
echo "<h3>Your message has been sent!</h3>";
echo "<p>Please print the following for your records:</p>";
echo "<p><b>Subject:</b> $subject</p>";
echo "<p>$Jay<br>";
echo "$Richard<br>";
echo "$Nancy<br>";
echo "$Julie<br>";
echo "<p><b>E-mail:</b><br>$email</p>";
echo "<p><b>Additional Employees:</b> <br>";
echo "$question</p>";
} else {
echo "There was an error...";
}
?>
<div><h3>For your records.</h3> <p>You should also recieve an e-mail with all the information that you just filled out.</p>
</div>
<?php
}
}
if(!isset($_POST['send']) || $errmsg != '')
{
?>
<div align="left" class="errmsg"><?=$errmsg;?></div>
<form id="msgform" name="msgform" method="post">
<table id="ValidCheckbox4" width="620">
<caption>
<div style="font-style:normal; text-align: left;"><h3>Center Engagement Comm Develop</h3></div>
</caption>
<tbody>
</tbody>
<tr>
<td valign="top">
<?php
//set file to read
$file = 'Computing_Telecom_Services.txt';
//open file
$fh = fopen($file, 'r') or die('Could not open file');
//read file contents
$data = fread($fh, filesize($file)) or die('Could not read file!');
//close file
fclose($fh);
//print file contents
echo $data;
?>
</td>
</tr>
</table>
<input name="send" type="submit" id="send" value="Send it">
<!--<input type="submit" value="Send it"/>-->
<input type="reset" value="Reset"/>
</form>
<?php
}
function isEmail($email)
{
return(preg_match("/^[-_.[:alnum:]]+@((([[:alnum:]]|[[:alnum:]][[:alnum:]-]*[[:alnum:]])\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co |com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|h n|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|m q|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc |sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za| zm|zw)$|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i"
,$email));
}
?>
[CODE]
There will be multiple forms for different areas of our business so the number of names is unknown. Then I need to mail their selection off when they hit submit.
I have been able to do this manually but with some 150 forms I don't have the time to devote souly to this. Plus there has to be an easier way. Hopefully?
[CODE]
<?php
$errmsg = 'Could not send file!'; // error message
if(isset($_POST['send']))
{
$Jay=($_POST['Jay'])?"Jay Alloway: Yes":"Jay Alloway: No";
$Richard=($_POST['Richard'])?"Richard Becker: Yes":"Richard Becker: No";
$Nancy=($_POST['Nancy'])?"Nancy Becker: Yes":"Nancy Becker: No";
$Julie=($_POST['Julie'])?"Julie Bell: Yes":"Julie Bell: No";
$email = $_POST['email'];
$question = $_POST['question'];
$subject = 'Constituency Employee Verification';
$headers = "MIME-Version: 1.0\r\n";
$headers = "Content-type: text/html; charset=iso-8859-1\r\n";
$headers = "Content-Transfer-Encoding: 7bit\r\n";
$headers = "From: $email\r\n";
if(trim($email) == '')
{
$errmsg = 'Please enter your email address';
}
else if(!isEmail($email))
{
$errmsg = 'Your email address is not valid';
}
if($errmsg == '')
{
if(get_magic_quotes_gpc())
{
$question = stripslashes($question);
}
// the email will be sent here
$to = "shaunk@found.ksu.edu";
// the email subject ( modify it as you wish )
$subject = 'Results from Academic Services Technology Verification form' ;
// the mail message ( add any additional information if you want )
$msg = "$Jay \n$Richard \n$Nancy \n$Julie \n\nE-mail = $email \n\nAdditional Employees = $question \n\n " . $message;
//mail($to, $subject, $msg, "From: $from\r\nReply-To: $from\r\nReturn-Path: $from\r\n");
$mailsent = mail("$to,$email", $subject, $msg, $headers);
if (mailsent) {
echo "<h2>Thank you for filling out our Constituency Employee form!</h2>";
echo "<h3>Your message has been sent!</h3>";
echo "<p>Please print the following for your records:</p>";
echo "<p><b>Subject:</b> $subject</p>";
echo "<p>$Jay<br>";
echo "$Richard<br>";
echo "$Nancy<br>";
echo "$Julie<br>";
echo "<p><b>E-mail:</b><br>$email</p>";
echo "<p><b>Additional Employees:</b> <br>";
echo "$question</p>";
} else {
echo "There was an error...";
}
?>
<div><h3>For your records.</h3> <p>You should also recieve an e-mail with all the information that you just filled out.</p>
</div>
<?php
}
}
if(!isset($_POST['send']) || $errmsg != '')
{
?>
<div align="left" class="errmsg"><?=$errmsg;?></div>
<form id="msgform" name="msgform" method="post">
<table id="ValidCheckbox4" width="620">
<caption>
<div style="font-style:normal; text-align: left;"><h3>Center Engagement Comm Develop</h3></div>
</caption>
<tbody>
</tbody>
<tr>
<td valign="top">
<?php
//set file to read
$file = 'Computing_Telecom_Services.txt';
//open file
$fh = fopen($file, 'r') or die('Could not open file');
//read file contents
$data = fread($fh, filesize($file)) or die('Could not read file!');
//close file
fclose($fh);
//print file contents
echo $data;
?>
</td>
</tr>
</table>
<input name="send" type="submit" id="send" value="Send it">
<!--<input type="submit" value="Send it"/>-->
<input type="reset" value="Reset"/>
</form>
<?php
}
function isEmail($email)
{
return(preg_match("/^[-_.[:alnum:]]+@((([[:alnum:]]|[[:alnum:]][[:alnum:]-]*[[:alnum:]])\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co |com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|h n|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|m q|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc |sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za| zm|zw)$|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i"
,$email));
}
?>
[CODE]