• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

How to convert (this code) from ASP to PHP?

madmatt

Bow Down to the King
Political User
#1
I am a pretty good ASP coder (maybe you'll think otherwise after seeing my code) and I am still learning PHP. I need to convert the following code from ASP to PHP. First one to help gets cookies!

Code:
  ' Start of workType Counter

  msgBody = msgBody & "<tr><td width=62% class=E1>When are you available to work?</td><td width=38% class=E1>"

  workTypeCount = 1
  workTypeCounter = Request.Form("workType").Count

  If workTypeCount <= workTypeCounter Then
    msgBody = msgBody & "<b>" & Request.Form("workType")(1) & " (" & Request.Form("fullTimeShift") & " Shift)</b><br>"
    workTypeCount = workTypeCount + 1
  End If
  If workTypeCount <= workTypeCounter Then
    msgBody = msgBody & "<b>" & Request.Form("workType")(2) & " (" & Request.Form("partTimeShift") & ")</b><br>"
    workTypeCount = workTypeCount + 1
  End If
  If workTypeCount <= workTypeCounter Then
    msgBody = msgBody & "<b>" & Request.Form("workType")(3) & " (" & Request.Form("tempDate1") & "-" & Request.Form("tempDate2") & ")</b>"
    workTypeCount = workTypeCount + 1
  End If

  msgBody = msgBody & "</td></tr>"

  ' End of workType Counter
Thank you.
 
#2
Maybe this

PHP:
<?php
// ' Start of workType Counter
// 
//   msgBody = msgBody & "<tr><td width=62% class=E1>When are you available to work?</td><td width=38% class=E1>"
// 
//   workTypeCount = 1
//   workTypeCounter = Request.Form("workType").Count
// 
//   If workTypeCount <= workTypeCounter Then
//     msgBody = msgBody & "<b>" & Request.Form("workType")(1) & " (" & Request.Form("fullTimeShift") & " Shift)</b><br>"
//     workTypeCount = workTypeCount + 1
//   End If
//   If workTypeCount <= workTypeCounter Then
//     msgBody = msgBody & "<b>" & Request.Form("workType")(2) & " (" & Request.Form("partTimeShift") & ")</b><br>"
//     workTypeCount = workTypeCount + 1
//   End If
//   If workTypeCount <= workTypeCounter Then
//     msgBody = msgBody & "<b>" & Request.Form("workType")(3) & " (" & Request.Form("tempDate1") & "-" & Request.Form("tempDate2") & ")</b>"
//     workTypeCount = workTypeCount + 1
//   End If
// 
//   msgBody = msgBody & "</td></tr>"
// 
//   ' End of workType Counter

$msgBody = "<tr><td width=62% class=E1>When are you available to work?</td><td width=38% class=E1>";

$workTypeCount = 1;
$workTypecounter = count($_POST['workType']);

if ($workTypeCount <= $workTypeCounter) {
    $msgBody .= "<b>" . $_POST['workType'][1] . " (" . $_POST['fullTimeShift'] . " Shift)</b><br>";
    $workTypeCount += 1;
}

if ($workTypeCount <= $workTypeCounter) {
    $msgBody .= "<b>" . $_POST['workType'][2] . " (" . $_POST['partTimeShift'] . ")</b><br>";
    $workTypeCount += 1;
}

if ($workTypeCount <= $workTypeCounter) {
    $msgBody .= "<b>" . $_POST['workType'][3] . " (" . $_POST['tempDate1']  . "-" $_POST['tempDate2'] . ")</b><br>";
    $workTypeCount += 1;
}

$msgBody .= "</td></tr>";
?>
 

madmatt

Bow Down to the King
Political User
#3
I'll give that a go. Thank you.

EDIT: No go. $workTypeCounter isn't being set so it doesn't go through the rest of the script.

EDIT #2: $workTypeCounter isn't being set correctly.

EDIT #3: Making progress. I found out that I needed to modify the name of my check boxes. I added a "[]" to the end and I am getting some where.
EDIT #4: Got it. Changing the array to 0 through 3 made it work perfectly. Thanks again Geffy.

PHP:
<?php

  $msgBody = "<tr><td width=62% class=E1>When are you available to work?</td><td width=38% class=E1>\n";

  $workTypeCount = 1;
  $workTypeCounter = count($_POST['workType']);

  if ($workTypeCount <= $workTypeCounter) {
    $msgBody .= "<b>" .$_POST['workType'][0] ." (" .$_POST['fullTimeShift'] ." Shift)</b><br>\n";
    $workTypeCount += 1;
  }
  if ($workTypeCount <= $workTypeCounter) {
    $msgBody .= "<b>" .$_POST['workType'][1] ." (" .$_POST['partTimeShift'] ." Time)</b><br>\n";
    $workTypeCount += 1;
  }
  if ($workTypeCount <= $workTypeCounter) {
    $msgBody .= "<b>" .$_POST['workType'][2] ." (" .$_POST['tempDate1']  ."-" .$_POST['tempDate2'] .")</b><br>\n";
    $workTypeCount += 1;
  }

  $msgBody .= "</td></tr>\n";

?>
EDIT #5: Of course this method breaks my error checking.

Code:
  var multiCheckbox = false;
  for (i = 0; i < document.app.workType.length; i++) {
    if (document.app.workType[i].checked)
    multiCheckbox = true;
  }
  if (!multiCheckbox) {
    errorMsg += "\nWork Availability\nPlease select full-time, part-time, and/or temporary.\n";
  }
 
Last edited:

Members online

No members online now.

Latest posts

Latest profile posts

Perris Calderon wrote on Electronic Punk's profile.
Ep, glad to see you come back and tidy up...did want to ask a one day favor, I want to enhance my resume , was hoping you could make me administrator for a day, if so, take me right off since I won't be here to do anything, and don't know the slightest about the board, but it would be nice putting "served administrator osnn", if can do, THANKS

Been running around Quora lately, luv it there https://tinyurl.com/ycpxl
Electronic Punk wrote on Perris Calderon's profile.
All good still mate?
Hello, is there anybody in there? Just nod if you can hear me ...
Xie
What a long strange trip it's been. =)

Forum statistics

Threads
61,962
Messages
673,240
Members
89,015
Latest member
loxioalix