Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

please give me tips on simplifing this code (its my first php script)

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
(
case 3:
print &quot;<script language=\&quot;JavaScript1.2\&quot; src=\&quot;st3.js\&quot;></script>&quot;;
print &quot;<form method=\&quot;post\&quot; action=\&quot;form.php?st=4\&quot;>&quot;;
print &quot;<input type=\&quot;hidden\&quot; name=\&quot;Hplan\&quot; value=\&quot;$Hplan\&quot;>&quot;;
print &quot;<input type=\&quot;hidden\&quot; name=\&quot;Dplan\&quot; value=\&quot;$Dplan\&quot;>&quot;;
if(isset($siteDescript)){
print &quot;<input type=\&quot;hidden\&quot; name=\&quot;haveURL\&quot; value=\&quot;$haveURL\&quot;>&quot;;
print &quot;<input type=\&quot;hidden\&quot; name=\&quot;similarSite\&quot; value=\&quot;$similarSite\&quot;>&quot;;
print &quot;<input type=\&quot;hidden\&quot; name=\&quot;siteDescript\&quot; value=\&quot;$siteDescript\&quot;>&quot;;
}
print &quot;<input type=\&quot;hidden\&quot; name=\&quot;name\&quot; value=\&quot;$fullName\&quot;>&quot;;
print &quot;<input type=\&quot;hidden\&quot; name=\&quot;compName\&quot; value=\&quot;$compName\&quot;>&quot;;
print &quot;<input type=\&quot;hidden\&quot; name=\&quot;add1\&quot; value=\&quot;$add1\&quot;>&quot;;
print &quot;<input type=\&quot;hidden\&quot; name=\&quot;add2\&quot; value=\&quot;$add2\&quot;>&quot;;
print &quot;<input type=\&quot;hidden\&quot; name=\&quot;city\&quot; value=\&quot;$city\&quot;>&quot;;
print &quot;<input type=\&quot;hidden\&quot; name=\&quot;state\&quot; value=\&quot;$state\&quot;>&quot;;
print &quot;<input type=\&quot;hidden\&quot; name=\&quot;zip\&quot; value=\&quot;$zip\&quot;>&quot;;
print &quot;<input type=\&quot;hidden\&quot; name=\&quot;email\&quot; value=\&quot;$email\&quot;>&quot;;
print &quot;<input type=\&quot;hidden\&quot; name=\&quot;dayPhone\&quot; value=\&quot;$dayPhone\&quot;>&quot;;
print &quot;<input type=\&quot;hidden\&quot; name=\&quot;evePhone\&quot; value=\&quot;$evePhone\&quot;>&quot;;
print &quot;<input type=\&quot;hidden\&quot; name=\&quot;fax\&quot; value=\&quot;$fax\&quot;>&quot;;
$body=&quot;<h1>Customer Info</h1>\n\n&quot;;
$body=&quot;Name:\t$fullName<br><br>&quot;;
$body+=&quot;Company:\t$compName<br><br>&quot;;
$body+=&quot;Address(line 1):\t$add1<br><br>&quot;;
$body+=&quot;Address(line 2):\t$add2<br><br>&quot;;
$body+=&quot;City:\t$city<br><br>&quot;;
$body+=&quot;State:\t$state<br><br>&quot;;
$body+=&quot;Zip:\t$zip<br><br>&quot;;
$body+=&quot;E-mail:\t$email<br><br>&quot;;
$body+=&quot;Day Phone:\t$dayPhone<br><br>&quot;;
$body+=&quot;Evening Phone:\t$evePhone<br><br>&quot;;
$body+=&quot;Fax:\t$fax<br><br>&quot;;
$body+=&quot;<h1>Billing Info</h1>\n\n&quot;;
$body+=&quot;Payment Type:\t$payment<br><br>&quot;;
if($payment != &quot;checkMO&quot;){
$body += &quot;Name On Card:\t$nameOnCard<br><br>&quot;;
$body += &quot;Card Number:\t&quot;;
$body += &quot;Exp Month and Year:\t$expMonth\\$expYear<br><br>&quot;;
}
if(!creditCardSame){
$body+=&quot;Billing Address(Line1):\t$BILLadd1<br><br>&quot;;
$body+=&quot;Billing Address(Line1):\t$BILLadd1<br><br>&quot;;
$body+=&quot;Billing City:\t$BILLcity<br><br>&quot;;
$body+=&quot;Billing State:\t$BILLstate<br><br>&quot;;
$body+=&quot;State:\t$state<br><br>&quot;;
}
else{
$body+=&quot;<b>USE CUSTOMER INFO FOR BILLING INFO</b><br><br>&quot;;
}
$body+=&quot;<h1>HOSTING PLAN</h1>&quot;;
$body+=&quot;Plan:\t$Hplan<br><br>&quot;;
if(isset($siteDescript)){
$body+=&quot;<h1>DESIGN PLAN</h1>&quot;;
$body+=&quot;Plan:\t$Dplan<br><br>&quot;;
$body+=&quot;Existing URL:\t$haveURL<br><br>&quot;;
$body+=&quot;Similar URL:\t$similarSite<br><br>&quot;;
$body+=&quot;Site Description:\t$siteDescript<br><br>&quot;;
}
print &quot;$body&quot;;
print &quot;<table border=\&quot;0\&quot; bgcolor=\&quot;yellow\&quot;>&quot;;
print &quot; <tr>&quot;;
print &quot; <td width=\&quot;150\&quot;>Payment Type*</td>&quot;;
print &quot; <td width=\&quot;250\&quot;><select size=\&quot;1\&quot; name=\&quot;payment\&quot;>&quot;;
print &quot; <option value=\&quot;visa\&quot;>Visa</option>&quot;;
print &quot; <option value=\&quot;master\&quot;>Master Card</option>&quot;;
print &quot; <option value=\&quot;amEx\&quot;>American Express</option>&quot;;
print &quot; <option value=\&quot;discover\&quot;>Discover</option>&quot;;
print &quot; <option value=\&quot;checkMO\&quot;>Check/Money Order</option>&quot;;
print &quot; </select>&quot;;
print &quot; </td>&quot;;
print &quot; </tr>&quot;;
print &quot; <tr>&quot;;
print &quot; <td width=\&quot;150\&quot;>Expiration Date</td>&quot;;
print &quot; <td width=\&quot;250\&quot;><select name=\&quot;expMonth\&quot; size=\&quot;1\&quot;>&quot;;
print &quot; <option VALUE=\&quot;01\&quot; SELECTED > Jan </option>&quot;;
print &quot; <option VALUE=\&quot;02\&quot; > Feb </option>&quot;;
print &quot; <option VALUE=\&quot;03\&quot; > Mar </option>&quot;;
print &quot; <option VALUE=\&quot;04\&quot; > Apr </option>&quot;;
print &quot; <option VALUE=\&quot;05\&quot; > May </option>&quot;;
print &quot; <option VALUE=\&quot;06\&quot; > Jun </option>&quot;;
print &quot; <option VALUE=\&quot;07\&quot; > Jul </option>&quot;;
print &quot; <option VALUE=\&quot;08\&quot; > Aug </option>&quot;;
print &quot; <option VALUE=\&quot;09\&quot; > Sep </option>&quot;;
print &quot; <option VALUE=\&quot;10\&quot; > Oct </option>&quot;;
print &quot; <option VALUE=\&quot;11\&quot; > Nov </option>&quot;;
print &quot; <option VALUE=\&quot;12\&quot; > Dec </option>&quot;;
print &quot; </select>&quot;;
print &quot; <select name=\&quot;expYear\&quot; size=\&quot;1\&quot;>&quot;;
print &quot; <option VALUE=\&quot;01\&quot; SELECTED> 2001 </option>&quot;;
print &quot; <option VALUE=\&quot;02\&quot; > 2002 </option>&quot;;
print &quot; <option VALUE=\&quot;03\&quot; > 2003 </option>&quot;;
print &quot; <option VALUE=\&quot;04\&quot; > 2004 </option>&quot;;
print &quot; <option VALUE=\&quot;05\&quot; > 2005 </option>&quot;;
print &quot; <option VALUE=\&quot;06\&quot; > 2006 </option>&quot;;
print &quot; <option VALUE=\&quot;07\&quot; > 2007 </option>&quot;;
print &quot; <option VALUE=\&quot;08\&quot; > 2008 </option>&quot;;
print &quot; </select></td>&quot;;
print &quot; </tr>&quot;;
print &quot; <tr>&quot;;
print &quot; <td width=\&quot;150\&quot;>Name On Card</td>&quot;;
print &quot; <td width=\&quot;250\&quot;><input type=\&quot;text\&quot; size=\&quot;30\&quot; maxlength=\&quot;50\&quot; name=\&quot;nameOnCard\&quot;></td>&quot;;
print &quot; </tr>&quot;;
print &quot; <tr>&quot;;
print &quot; <td colspan=\&quot;2\&quot;>Is your contact address the same as your billing address?<input NAME=\&quot;creditCardSame\&quot; TYPE=\&quot;checkbox\&quot; checked></td>&quot;;
print &quot; </tr>&quot;;
print &quot; <tr>&quot;;
print &quot; <td width=\&quot;150\&quot;>Address- Line1*&nbsp;</td>&quot;;
print &quot; <td width=\&quot;250\&quot;><input type=\&quot;text\&quot; size=\&quot;30\&quot; maxlength=\&quot;50\&quot; name=\&quot;BILLadd1\&quot;></td>&quot;;
print &quot; </tr>&quot;;
print &quot; <tr>&quot;;
print &quot; <td width=\&quot;150\&quot;>Address- Line 2</td>&quot;;
print &quot; <td width=\&quot;250\&quot;><input type=\&quot;text\&quot; size=\&quot;30\&quot; maxlength=\&quot;50\&quot; name=\&quot;BILLadd2\&quot;></td>&quot;;
print &quot; </tr>&quot;;
print &quot; <tr>&quot;;
print &quot; <td width=\&quot;150\&quot;>City*</td>&quot;;
print &quot; <td width=\&quot;250\&quot;><input type=\&quot;text\&quot; size=\&quot;15\&quot; maxlength=\&quot;30\&quot; name=\&quot;BILLcity\&quot;></td>&quot;;
print &quot; </tr>&quot;;
print &quot; <tr>&quot;;
print &quot; <td width=\&quot;150\&quot;>State*</td>&quot;;
print &quot; <td width=\&quot;250\&quot;><input type=\&quot;text\&quot; size=\&quot;10\&quot; maxlength=\&quot;25\&quot; name=\&quot;BILLstate\&quot;></td>&quot;;
print &quot; </tr>&quot;;
print &quot; <tr>&quot;;
print &quot; <td width=\&quot;150\&quot;>Zip Code*</td>&quot;;
print &quot; <td width=\&quot;250\&quot;><input type=\&quot;text\&quot; size=\&quot;5\&quot; maxlength=\&quot;10\&quot; name=\&quot;BILLzip\&quot;></td>&quot;;
print &quot; </tr>&quot;;
print &quot; <tr><td valign=\&quot;top\&quot; colspan=\&quot;2\&quot; width=\&quot;400\&quot;><b>AGREEMENT TO TERMS</b><br>&quot;;
print &quot; By typing your name in the&nbsp; &quot;On-line Signature&quot; below, and pressing the&quot;;
print &quot; &quot;Purchase Now&quot; button below, you hereby agree to the <a href=\&quot;terms.htm\&quot; target=\&quot;_blank\&quot;>Terms and&quot;;
print &quot; Conditions</a> and hereby authorize all expenses associated with this account.&quot;;
print &quot; Additionally, any monthly, quarterly or annual charges are authorized to be billed, when&quot;;
print &quot; due, to this account.&quot;;
print &quot; </td></tr>&quot;;
print &quot; <tr>&quot;;
print &quot; <td width=\&quot;150\&quot;>Online Signature*</td>&quot;;
print &quot; <td width=\&quot;250\&quot;><input type=\&quot;text\&quot; size=\&quot;30\&quot; maxlength=\&quot;50\&quot; name=\&quot;Signature\&quot;></td>&quot;;
print &quot; </tr>&quot;;
print &quot;If the above info is correct proceed by pressing process<br>&quot;;
print &quot;<input type=\&quot;submit\&quot; value=\&quot;process\&quot; size=\&quot;20\&quot; onClick>&quot;;
break;
 
Wow... did you know that the whole page doesn't have to be in PHP? That's the beauty of scripting languages, you can script what you need and use it in conjunction with regular HTML code. For example, you can do

<?php case 3: ?>
<script language=&quot;JavaScript1.2&quot; src=&quot;st3.js&quot;></script>
<form method=&quot;post&quot; action=&quot;form.php?st=4&quot;>
<input type=&quot;hidden&quot; name=&quot;Hplan&quot; value=&quot;<?php echo $Hplan; ?>&quot;>
...
Exp Month and Year: <?php echo $expMonth . &quot;\&quot; . $expYear; ?><br><br>
<?php if (!creditCardSame) { ?>
Billing Address(Line1): <?php echo $BILLadd1; ?><br><br>
...
<?php } else { ?>
...
<?php break; ?>

Etc. Also when you concatenate strings you need to use .= not += (which works to add numbers together).

Hope that helps!
 
You should always be aware of the point, that you can use as many php scripts in you document as you like. Will say, that you use a louse html form and add some code where it is needed. If you want to change the values of a form after the data is entered you may should do that in a second document after the form validation. Any input field will have a corressponding variable in the target document of your form.
If you must generate a form like this, you could also look for html statements that repeat very often and put them in a variable. This would shorten your code alot, but the example above is more or less a usual html doc and should be treaten like that.

</imagetag>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top