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

madmatt

Awesome is as awesome does.
Political Access
Joined
5 Apr 2002
Messages
13,314
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.
 
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>";
?>
 
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:
Just a question, but if you are using a three tiered array shouldn't your set be 0,1,2?
 
He's caught that. Sorry I'd just done a pretty much line by line port of the ASP without checking things like indexes 😛

my bad
 

Members online

No members online now.

Forum statistics

Threads
62,021
Messages
673,242
Members
5,639
Latest member
Everlong
Back
Top