Jump to content

Php Form Prossesing Script


pagemaker

Recommended Posts

Hi Everyone I hope that I can find some help here is possible. Here is my problem;

I am using phpsimplescript.php to process my forms. It works well but the out put is all over the page. I need to be able to organize the output in order. The questions are in order and on the left side of the page but the answers although on the correct line are some on the left side some in the middle on some on the right side of the page. I would like to be able to line them up one under the other in an even order like the questions are.

 

Here is a copy of  the script.

 

<?php


//--------------------------Set these paramaters--------------------------


$subject = 'New Homestay Application';                // Subject of email sent to you.
$emailadd = '[email protected]';        // Your email address. This is where the form information will be sent.
$url = 'http://www.mydomain.com/forms/thankyou.html';               // Where to redirect after form is processed.
$req = '0';                                  // 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.

// --------------------------Do not edit below this line--------------------------
$text = "Results from Application 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 30 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.'">';
?>

 

Here is a sample of the output I get;

 

Results from Application form:

subject:         The DEWBERRY HOMESTAY Application
realname:          Larry Snow
email:       [email protected]
Telephone:           780-761-7484
Fax:     
Gender:        Male
Age:     57
Guest_Address:               16633 - 99th. Avenue N.W.
City:      Edmonton
Province_State:                Alberta
Postal_Zip:            T5B 4H1
Country:         Canada
Check_in_Month:                January
Check_in_Day:              01
Check_in_Year:               2010
Check_Out_Month:                 September
Check_Out_Day:               30
Check_Out_Year:                2010
Student_Visa:              No
Work_Visa:           Yes
Health_Insurance:                  Yes
Room_Selection:                Room 2 Option 1 Monthly Fee $803.00 (USD) or $850.00 (CDN) Meals Included
Airport_Pickup:                Yes $25.00
Name_of_Airline:                 Air Canada
Flight_Number:               521
Arrival_Time:              2:45 pm
Arrival_Month:               January
Arrival_Day:             01
Arrival_Year:              2010
Emergency_Contact:                   Diana Snow
Relationship:              Wife
Language:          English
contactemail:              [email protected]
Contact_Phone:               same
Contact_Address:                 same
Contact_City:              same
Contact_P/S:             same
Contact_Postal_Zip:                    same
Contact_Country:                 same
Allergies_Dietary:                   I do not have any Allergies or Dietary needs.
Comments:          Pleas lt me know as soon as possible as I will complete my travel plans. Thank you.

Submit:        Send Application Request

 

Amy help with this problem would be great. Thank you in advance for your help.

 

Link to comment
https://forums.phpfreaks.com/topic/185824-php-form-prossesing-script/
Share on other sites

Its the font the recipient uses as a system font or what the email client uses. Take this code and run it.

 

$array = array('aaaaaaaa'=>'aaaa', 'aaaaaaaaaa'=>'aaaaaaaaaaaaaaaaaaaaa','aaa' => 'aaaaaaa');

foreach ($array as $key => $value)

{

  if ($req == '1')

  {

      if ($value == '')

      {echo "$key is empty";die;}

  }

  $j = strlen($key);

      $len = 30-$j;

 

        for ($i = 1; $i <= $len; $i++)

        {

        $space.='a';

        }

        $ll=$j+$len;

  $out.="[$j:$len:$ll]$key:$space-$value\n<br>";

  $space='';

}

echo "$out";

 

See how the hyphens line up? That means the spacer is doing what you wish. Now take and change all the "a" to something meaningful like(notice all have a 3-7-6 model):

fname=>joe  charles idamir

address=>123 waverly street

city=>san campagi bow

and in the foreach change the spacer to $space='.';

we need to use a dot or something cause we are looking at thins in a browser and a browser will display only one space, hence the use of " "

for extra spaces(which is not its designated use).

And see what you get, you think they all equal out, but it depends on your font.

 

The reason is that not all fonts use the same points for a character. Some use the same width for each character(mono-spaced) others use the displayed width of the character(proportional-spaced). So in some fonts i and w will be the same width and other fonts the w would equal about 2.5 of the i's.  To understand more use the wiki, it explains it probably better than I can:

http://en.wikipedia.org/wiki/Typeface

 

 

HTH

Teamatomic

I did as you suggested and resubmitted the form again this is all I got.

 

Results from Application form:

 

aaaaaaaa: .            aaaa

aaaaaaaaaa: .          aaaaaaaaaaaaaaaaaaaaa

aaa: .                  aaaaaaa

 

No other form information was sent.

My apology;

I was not asking for someone to write the code for me, although that would have been nice. I am very new to php and really don’t understand it and was just asking for some help. Thought that’s what the forum was. Guess I was wrong. Very sorry to have bothered you here.

 

Kindest Regards

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.