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

madmatt

Bow Down to the King
Political User
Joined
Apr 5, 2002
Messages
13,312
#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.
 

Geffy

OSNN Veteran Addict
Joined
Mar 18, 2002
Messages
7,805
#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
Joined
Apr 5, 2002
Messages
13,312
#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:

falconguard

Carbon based lifeform
Political User
Joined
Feb 11, 2004
Messages
3,406
#4
Just a question, but if you are using a three tiered array shouldn't your set be 0,1,2?
 

Geffy

OSNN Veteran Addict
Joined
Mar 18, 2002
Messages
7,805
#5
He's caught that. Sorry I'd just done a pretty much line by line port of the ASP without checking things like indexes :p

my bad
 

Members online

No members online now.

Latest profile posts

Perris Calderon wrote on Electronic Punk's profile.
Hey ep!

All good with me, applying for microsoft mvp right now, should have done this a while ago.

Notifications don't work, I only found your response by comming back to hunt up some threads, if you want, give me your email address so we can keep in touch easier, mine is perriscalderon at gmail
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 ...

Forum statistics

Threads
62,035
Messages
673,561
Members
89,039
Latest member
Rosacantu