Jump to content

Recommended Posts

OK, I've got a simple application form. Look below:

http://www.rnkprofessionalcorporation.com/website/application.htm

 

Once someone clicks submit, how do I make it send me all those information in a well organized format? To a file on my server or e-mail?

 

What would I have to be the code in the process.php?  :shrug:

Link to comment
https://forums.phpfreaks.com/topic/166343-need-help-with-simple-application-form/
Share on other sites

in a well organized format? To a file on my server or e-mail?

 

I think this is the first thing you have to decide.  How do you want the data?

From there, a super simplified mail script looks like this

<?php 
$body = $_POST['First_name'] ."<br>";
$body .= $_POST['Last_name'] ."<br>";
mail($to, $subject, $body, $headers) ?>

Again yours to decide what the variables contain.

 

Or as saving a file to your server

<?php
$file = fopen("test.txt","w");
$body = $_POST['First_name'] ."<br>";
$body .= $_POST['Last_name'] ."<br>";
echo fwrite($file,$body);
fclose($file);
?>

That said, you really shouldn't overpost your questions

Thanks... That looks like the exact code I'm looking for except a few conditions....

 

For each new application it is overwriting into test.txt. How would I have it make new .txt files for each new application?

 

Also this is what I'm getting as output....

 

John<br>Smith<br>

 

It's not using <br> properly... how to fix this?

You need to tell the script to change the name of the text file each time it runs. The simplest way would be to generate a random name and append it to the file.

i.e.

 

<?php

//Create a random 10-digit alphanumeric variable
function randomgen() {
$length = 10;
$string = 'abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$key = substr( str_shuffle($string), 0, $length ); 
return $key;
}

$filename = randomgen();

$file = fopen("$filename.txt","w");
$body = $_POST['First_name'] ."<br>";
$body .= $_POST['Last_name'] ."<br>";
echo fwrite($file,$body);
fclose($file);
?>

 

Regarding

"John<br>Smith<br>"

 

You've created a text file, it is not able to print in HTML.

You would need to change the file extension, or change how you're inputting data into test.txt

I am trying to make it display like such......

 

First name: Joe

Last name: Smith

 

with the code...

 

<?php

//Create a random 10-digit alphanumeric variable
function randomgen() {
$length = 10;
$string = 'abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$key = substr( str_shuffle($string), 0, $length ); 
return $key;
}

$filename = randomgen();

$file = fopen("$filename.html","w");
$body = ."<b>First name</b>" $_POST['First_name'] ."<br>";
$body .= ."<b>First name</b>" $_POST['Last_name'] ."<br>";
echo fwrite($file,$body);
fclose($file);
?>

 

What's wrong? I'm getting this error...

 

Parse error: syntax error, unexpected '.' in /home/adfinanc/public_html/process.php on line 14

make

 

$body = ."<b>First name</b>" $_POST['First_name'] ."<br>";
$body .= ."<b>First name</b>" $_POST['Last_name'] ."<br>";

 

into

 


$body="<b>First name</b> ".$_POST['First_name']."<br>";
$body.="<b>Last name</b> ".$_POST['Last_name']."<br>";

 

lemme know

In order to make the text files appear in numeric order you need to know the next number which means you need to store the value somewhere. The easiest way is to simply write the number to a text file each time. Then you just read the number and add 1 to it every time a new e-mail is sent. You could also store it in the database if that seems easier. Another way would be to check which text files exist already and get next number that way but that means unnecessary work.

 

Also, always be on the lookout for mail injections when sending e-mails with form data.

Hey.... this is my last question. Please help me out.

 

For the output, I want to display like this:

 

First name: John                              Last Name: Smith

Address: 12 Cherry street ave            City: London

Province: Ontario                              Postal Code: A1B 2C3

 

I've tried to make a code but it keeps displaying error.... I want the column of Last Name, City, Postal Code, etc. all to be aligned perfectly. Is this possible? How will the code look like in process.php?

you may want to use css for this and use defined widths to make the columns lined up

 

this is what you would be doing on a very basic level

.columns {
   float:left;
   width:200px;
}

<div class="columns">
<?php
   echo "first name";
   echo "address";
   echo "province";
?>
</div>
<div class="columns">
<?php
   echo "last name";
   echo "city";
   echo "postal code";
?>

</div>

<?php

//Create a random 10-digit alphanumeric variable
function randomgen() {
$length = 10;
$string = 'abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$key = substr( str_shuffle($string), 0, $length ); 
return $key;
}

$filename = randomgen();

$file = fopen("$filename.html","w");

$body="<table border="0" width="502" height="50" id="table1">
<tr>
	<td height="46" width="240">
	<font face="Verdana" size="2">First name: </font><font face="Verdana"><font size="2">   </font>".$_POST['First_name']."<font size="2">
	<br>Address:    
	  </font><font style="font-size: 5pt"> </font>"
	.$_POST['Address']."</td>
	<td height="46" width="246">
	<font face="Verdana">
	<font size="2">Last Name:      
	</font>".$_POST['Last_name']."<font size="2">
	City: 
	            
	</font><font style="font-size: 6pt"> </font>".$_POST['City']."<font size="2">
	</font></font></td>
	</td>
</tr>
</table>";


echo fwrite($file,$body);
fclose($file);
?>

 

Parse error: syntax error, unexpected T_LNUMBER in /home/adfinanc/public_html/application/process.php on line 15

you may want to use css for this and use defined widths to make the columns lined up

 

this is what you would be doing on a very basic level

.columns {
   float:left;
   width:200px;
}

<div class="columns">
<?php
   echo "first name";
   echo "address";
   echo "province";
?>
</div>
<div class="columns">
<?php
   echo "last name";
   echo "city";
   echo "postal code";
?>

</div>

was asking for code to put in process.php  :o

See this is what I used for process.php

 

<?php

//Create a random 10-digit alphanumeric variable
function randomgen() {
$length = 10;
$string = 'abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$key = substr( str_shuffle($string), 0, $length ); 
return $key;
}

$filename = randomgen();

$file = fopen("$filename.html","w");
$body="<b>First name: </b> ".$_POST['First_name']."                 
<b>Last Name: </b>" .$_POST['Last_name']."<br>";

$body.="<b>Address</b> ".$_POST['Address']."                 
<b>City: </b>" .$_POST['City']."<br>";


echo fwrite($file,$body);
fclose($file);
?>

 

And this is what i get as output....

 

First name: dsfsdsf                  Last Name: dsfd

Address dsfsd                  City: fsdfdsf

 

As you can see Last Name and City are not aligned. Can you please modify my process.php so this can be achieved?

<?php

//Create a random 10-digit alphanumeric variable
function randomgen() {
$length = 10;
$string = 'abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$key = substr( str_shuffle($string), 0, $length ); 
return $key;
}

$filename = randomgen();

$file = fopen("$filename.html","w");
$body="<table width=\"75%\" cellpadding=\"2\" cellspacing=\"2\">
<td><b>First name: </b>  
".$_POST['First_name']."</td><td>
<b>Last Name: </b>" .$_POST['Last_name']."</td><tr>";

$body.="<td><b>Address</b> ".$_POST['Address']." </td>
<td><b>City: </b>" .$_POST['City']."</td><tr>
</table>";


echo fwrite($file,$body);
fclose($file);
?>

 

I haven't tested this though. There may be errors.

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.