Form field ( 6 Views )
-
I have a form that has a few fields in it such as address that take inputs that may include a space. When I retrieve the data in the cgi script using the command:
$purchasing_company = param("purchasing_company");
I receive only the word before the first space. How do I correct this?
Thanks in advance for your help!
Lisa
(gökmen, Antigua and Barbuda)
that seems strange. post the troublesome code and we'll see what's wrong.
(SÜPHANE, Chile)
Here's the code:
#!/usr/bin/perl
use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser carpout);
$purchasing_company = param("purchasing_company");
$supplier = param("supplier");
$other_company = param("other_company");
$terms1 = param("terms1");
$terms2 = param("terms2");
$terms3 = param("terms3");
$terms4 = param("terms4");
$other_terms = param("other_terms");
$buyer = param("buyer");
$po_date = param("po_date");
$po_number = param("po_number");
$release_no = param("release_no");
$change_no = param("change_no");
$billing_address = param("billing_address");
$shipping_point_zip = param("shipping_point_zip");
$fob = param("fob");
$ship_to = param("ship_to");
$confirmed_date = param("confirmed_date");
$confirming_phone = param("confirming_phone");
$originator = param("originator");
$originator_phone = param("originator_phone");
$confirming_email = param("confirming_email");
$item1 = param("item1");
$item_description1 = param("item_description1");
$quantity1 = param("quantity1");
$part_number1 = param("part_number1");
$unit_price1 = param("unit_price1");
$delivery_date1 = param("delivery_date1");
$item2 = param("item2");
$item_description2 = param("item_description2");
$quantity2 = param("quantity2");
$part_number2 = param("part_number2");
$unit_price2 = param("unit_price2");
$delivery_date2 = param("delivery_date2");
$item3 = param("item3");
$item_description3 = param("item_description3");
$quantity3 = param("quantity3");
$part_number3 = param("part_number3");
$unit_price3 = param("unit_price3");
$delivery_date3 = param("delivery_date3");
$additional_info = param("additional_info");
print "Content-type: text/html\n\n";
print "<html><head><title>Print Purchase Order - ServSteel</title>";
print "<script language=\"JavaScript\" type=\"text/JavaScript\">";
print "<!--";
print "function MM_preloadImages() { //v3.0";
print "var d=document\; if(d.images){ if(!d.MM_p) d.MM_p=new Array()\;";
print "var i,j=d.MM_p.length,a=MM_preloadImages.arguments\; for(i=0\; i<a.length\; i++)";
print "if (a[i].indexOf(\"#\")!=0){ d.MM_p[j]=new Image\; d.MM_p[j++].src=a[i]\;}}";
print "}";
print "function MM_swapImgRestore() { //v3.0";
print "var i,x,a=document.MM_sr\; for(i=0\;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc\;";
print "}";
print "function MM_findObj(n, d) { //v4.01";
print "var p,i,x\; if(!d) d=document\; if((p=n.indexOf(\"?\"))>0&&parent.frames.length) {";
print "d=parent.frames[n.substring(p+1)].document\; n=n.substring(0,p)\;}";
print "if(!(x=d[n])&&d.all) x=d.all[n]\; for (i=0\;!x&&i<d.forms.length\;i++) x=d.forms[i][n]\;";
print "for(i=0\;!x&&d.layers&&i<d.layers.length\;i++) x=MM_findObj(n,d.layers[i].document)\;";
print "if(!x && d.getElementById) x=d.getElementById(n)\; return x\;\n";
print "}";
print "function MM_swapImage() { //v3.0";
print "var i,j=0,x,a=MM_swapImage.arguments\; document.MM_sr=new Array\; for(i=0\;i<(a.length-2)\;i+=3)";
print "if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x\; if(!x.oSrc) x.oSrc=x.src\; x.src=a[i+2]\;}";
print "}";
print "//-->";
print "</script>";
print "</head>";
print "<body>";
print "<table border=\"0\" width=\"418\" cellspacing=\"2\" cellpadding=\"2\" align=\"center\" bgcolor=\"#FFFFFF\">";
print "<tr><td class=\"green\"><b>PURCHASE ORDER</b></td><td align=\"right\"><a href=\"index.htm\">Return to home page</a></td></tr>";
print "<tr><td width=\"300\">Purchasing Company:<br> <input name=\"purchasing_company\" value=$purchasing_company size=\"40\"></td><td width=\"300\">Supplier: Servsteel, Inc<br /><input name=\"supplier\" value=$supplier size=\"40\"></td></tr>";
print "<tr><td valign=\"top\">-OR-<br />Type in your company name here: <input name=\"other_company\" value=$other_company type=\"text\" size=\"40\" maxlength=\"40\"><br /><br />Terms: <br /><input name=\"terms1\" type=\"checkbox\" value=$terms1>1% 10 days/Net 30<br /><input name=\"terms2\" type=\"checkbox\" value=$terms2>2% 15 days/Net 30<br /><input name=\"terms3\" type=\"checkbox\" value=$terms3>Net 30 days<br /><input name=\"terms4\" type=\"checkbox\" value=$terms4>Consignment<br />Other Terms: <input name=\"other_terms\" value=$other_terms type=\"text\" size=\"20\" maxlength=\"15\"><br /><br />Buyer: <input name=\"buyer\" value=$buyer type=\"text\" size=\"15\" maxlength=\"20\"></td>";
print "<td><table cellspacing=\"10\"><tr><td>P.O. Date:</td><td><input name=\"po_date\" value=$po_date type=\"text\" size=\"8\" maxlength=\"12\"></td></tr><tr><td>P.O. Number:</td><td><input name=\"po_number\" value=$po_number type=\"text\" size=\"10\" maxlength=\"12\"></td></tr><tr><td>Release No:</td><td><input name=\"release_no\" value=$release_no type=\"text\" size=\"5\" maxlength=\"5\"></td></tr><tr><td>Change No:</td><td><input name=\"change_no\" value=$change_no type=\"text\" size=\"2\" maxlength=\"2\"></td></tr><tr><td>Bill To:</td><td><textarea name=\"billing_address\" value=$billing_address cols=\"30\" rows=\"4\"></textarea></td></tr></table></tr>";
print "<tr><td class=\"green\" colspan=\"2\"><b>Delivery Information:</b></td></tr>";
print "<tr><td rowspan=\"2\"><table cellspacing=\"10\"><tr><td>Shipping Point Zip:</td><td><input name=\"shipping_point_zip\" value=$shipping_point_zip type=\"text\" size=\"5\" maxlength=\"9\"></td></tr><tr><td>FOB: </td><td><input name=\"fob\" value=$fob size=\"1\"></td></tr></table>";
print "</td><td rowspan=\"2\"><table><tr><td>Ship To:</td><td><textarea name=\"ship_to\" value=$ship_to cols=\"30\" rows=\"3\"></textarea></td></tr><tr><td>Receiving Hours:</td><td><textarea name=\"receiving_hours\" value=$receiving_hours cols=\"30\" rows=\"2\"></textarea></td></tr></table></td></tr>";
print "<tr><td colspan=\"2\"> </td></tr>";
print "<tr><td class=\"green\" colspan=\"2\"><b>For Confirming Orders:</b></td></tr>";
print "<tr><td colspan=\"4\">Confirmed to: <input name=\"confirming_name\" value=$confirming_name type=\"text\" size=\"15\" mxlength=\"20\"> \;  \;Date: <input name=\"confirmed_date\" value=$confirmed_date type=\"text\" size=\"12\" maxlength=\"12\"> \;  \;Phone: <input name=\"confirming_phone\" value=$confirming_phone type=\"text\" size=\"15\" maxlength=\"15\"></td></tr>\n};print {<tr><td colspan=\"4\">Originator: <input name=\"originator\" value=$originator type=\"text\" size=\"15\" maxlength=\"20\"> \;  \;Phone: <input name=\"originator_phone\" value=$originator_phone type=\"text\" size=\"12\" maxlength=\"12\"> \;  \;Email: <input name=\"confirming_email\" value=$confirming_email type=\"text\" size=\"15\" maxlength=\"35\"></td></tr>";
print "<tr><td colspan=\"3\"><table><tr><td>Item</td><td>Item Description</td><td>Quantity</td><td>Part Number</td><td>Unit Price</td><td>Delivery Date</td></tr>";
print "<tr><td><input name=\"item1\" value=$item1 type=\"text\" size=\"12\"></td><td><input name=\"item_description1\" value=$item_description1 type=\"text\" size=\"20\"></td><td><input name=\"quantity1\" value=$quantity1 type=\"text\" size=\"3\" maxlength=\"3\"></td><td><input name=\"part_number1\" value=$part_number1 type=\"text\" size=\"8\" maxlength=\"8\"></td><td><input name=\"unit_price1\" value=$unit_price1 type=\"text\" size=\"10\" maxlength=\"10\"></td><td><input name=\"delivery_date1\" value=$delivery_date1 type=\"text\" size=\"12\" maxlength=\"12\"></td></tr>";
print "<tr><td><input name=\"item2\" value=$item2 type=\"text\" size=\"12\"></td><td><input name=\"item_description2\" value=$item_description2 type=\"text\" size=\"20\"></td><td><input name=\"quantity2\" value=$quantity2 type=\"text\" size=\"3\" maxlength=\"3\"></td><td><input name=\"part_number2\" value=$part_number2 type=\"text\" size=\"8\" maxlength=\"8\"></td><td><input name=\"unit_price2\" value=$unit_price2 type=\"text\" size=\"10\" maxlength=\"10\"></td><td><input name=\"delivery_date2\" value=$delivery_date2 type=\"text\" size=\"12\" maxlength=\"12\"></td></tr>";
print "<tr><td><input name=\"item3\" value=$item3 type=\"text\" size=\"12\"></td><td><input name=\"item_description3\" value=$item_description3 type=\"text\" size=\"20\"></td><td><input name=\"quantity3\" value=$quantity3 type=\"text\" size=\"3\" maxlength=\"3\"></td><td><input name=\"part_number3\" value=$part_number3 type=\"text\" size=\"8\" maxlength=\"8\"></td><td><input name=\"unit_price3\" value=$unit_price3 type=\"text\" size=\"10\" maxlength=\"10\"></td><td><input name=\"delivery_date3\" value=$delivery_date3 type=\"text\" size=\"12\" maxlength=\"12\"></td></tr>";
print "</table></td></tr>";
print "<tr><td colspan=\"2\"><b>Additional Information:</b><br /><textarea name=\"additional_info\" value=$additional_info cols=\"110\" rows=\"5\"></textarea></td></tr></table>";
#print "<map name=\"Map\">}\n};
#print "<area shape=\"rect\" coords=\"7,1,52,16\" href=\"index.htm\">";
#print "<area shape=\"rect\" coords=\"61,0,105,16\" href=\"mailto:info@servsteelinc.com\">";
#print "</map>\n";
print "</body></html>\n";
#open (SENDMAIL1, "| /usr/lib/sendmail -t");
#print SENDMAIL1 <<End;
#To: lfox\@capitolwebdesign.net
#From: orders\@servsteelinc.com
#Subject: Purchase Order Submit
#purchasing_company,supplier,other_company,terms1,terms2,terms3,terms4,other_t erms,buyer,po_date,po_number,release_no,change_no,billing_address,shipping_poi nt_zip,fob,ship_to,receiving_hours,confirming_name,confirmed_date,confirming_p hone,originator,originator_phone,confirming_email,item1,item_description1,quan tity1,part_number1,unit_price1,delivery_date1,item2,item_description2,quantity 2,part_number2,unit_price2,delivery_date2,item3,item_description3,quantity3,pa rt_number3,unit_price3,delivery_date3,additional_info = param("additional_info");
#$purchasing_company,$supplier,$other_company,$terms1,$terms2,$terms3,$terms4, $other_terms,$buyer,$po_date,$po_number,$release_no,$change_no,$billing_addres s,$shipping_point_zip,$fob,$ship_to,$receiving_hours,$confirming_name,$confirm ed_date,$confirming_phone,$originator,$originator_phone,$confirming_email,$ite m1,$item_description1,$quantity1,$part_number1,$unit_price1,$delivery_date1,$i tem2,$item_description2,$quantity2,$part_number2,$unit_price2,$delivery_date2, $item3,$item_description3,$quantity3,$part_number3,$unit_price3,$delivery_date 3,$additional_info
#End
#close SENDMAIL1;
#open (SENDMAIL2, "| /usr/lib/sendmail -t");
#print SENDMAIL2 <<End;
#To: $confirming_email
#From: orders\@servsteelinc.com
#Subject: Purchase Order Confirmation
#Thank You for your Order!
#End
#close SENDMAIL2;
(Emre, Bahrain)
the problem lies in your html and not in the perl code. in your html element "purchasing_company" you are not quoting the value attribute like
Code:
<input type="text" value="$purchasing_company" name="purchasing_company" />
rather you have
Code:
<input type="text" value=$purchasing_company name="purchasing_company" />
Without quoting the html element value attribute, html only interprets the first word as the value of the 'value' attrribute. Any words following the spaces are interepreted as short-style attributes (similar to SELECT element's MULTIPLE attributes). You should always quote the values of html element attributes. Just for fun, see how html renders this code...
Code:
<html>
<head>
<title>test value</title>
</head>
<body>
<form>
<input type="text" value=foo bar baz name="t1" />
<br />
<input type="text" value="foo bar baz" name="t2" />
</form>
</body>
</html>
On a more troubling note, there are a number of serious security flaws in your code. For example, you don't do anything to ensure a safe environment before calling sendmail. Also you are not using taint mode (-T switch). While the Taint mode might not matter so much in this particular instance, it is a good habit to get into. The failure to ensure the sanity of the "PATH" environment variable can be much worse. It would allow a hacker to potentially set the PATH variable to somewhere other than you intend. Even if you explicitly set the path to sendmail, there is no guarantee that sendmail won't turn around and use the PATH variable to call another program. If the hacker knows what program sendmail will try to call, and they always do, he can execute a program of the same name that he/she has written which resides in the folder pointed to by his malicious PATH variable. The following is a good preamble to a perl script that calls sendmail...
Code:
#!/usr/bin/perl -wT
use strict;
BEGIN {
$ENV{PATH} = "/bin:/usr/bin";
delete @ENV{ qw( IFS CDPATH ENV BASH_ENV ) };
}
my $sendmail = '/path/to/sendmail/';
I would suggest reading the perlsec manpages - "perldoc perlsec" from the command line and to read the CGI manpages as well. There are a number of good tutorials on the web that refer to these types of common mistakes.
(berkcan, Jordan)
Thanks, ChaCha, that worked great!
I have a couple other questions.
1. The form has a set of checkboxes. How do I setup the code to have the
checked boxes come across and be checked on the response page included in
the CGI script?
2. There are a couple long text field such as "Additional Information"
that do not come across even with the quotes. Is there a way to bring
these large fields across from the form to the response page?
Thanks Again
(semih, Brazil)
for "sticky widgets", or fields that autopopulate themselves with the values of the last request, use CGI.pm and create all your form fields using the built in html generation functions. Just use "perldoc CGI" from the command line learn more. You may have to change the working directory to /Path/To/Perl/bin/. The command "perldoc <some module>" will display the built in documentation available for almost all modules distributed through CPAN.
Remember that <textarea> elements store take a default value inbetween the tags, not in a value attribute
Code:
<textarea>some default value</textarea>
you will have to place the text there if you want it to show up properly. But if you use the CGI.pm html gen functions the module will take care of that for you.
(nihan, Gabon)
Related Topics ... (or search in 1.720.883 topics !)
form field - validate <input type="checkbox"> in form field (2) how to retrieve form field value if form is enctype=multipart/form-data? (2) form method post, hidden field sent, input field not sent?? (2) if form.field=this, mailto user, if form.field=that mailto user2? (8) copy date from field to field in a form (4) way to pass form field value directly to landing page form. (2) form validation - field by field (5) force value of a form field based on 2 other form fields. (6) reset form field when form submitted to frame (2) form select values based upon another form field? (2)
copyright © 2007-2031 Pfodere.COM ( 5 Pfoyihuee Online )
|