processing forms with PHP
I am trying to process an email form using PHP.It is working okay so far but I want the Items to be displayed as a list when the email is received.
eg. one two three four and not one two three four here is a copy of the variable that displays the message |
Quote:
|
Variable I left out (item)
foreach ($_POST['MLIS'] as $item){
$items .= $item." "; } here is the copy of the variable I left out |
Quote:
|
could someone please explain to me why this codes sends only the information checked in the check boxes and not the text boxes.
<tr> <td><input type="checkbox" name="MLIS[]" value="Notepads" />Notepads</td> <td><input type="text" size="1" maxlength="2" onkeydown="val = this.value;" onkeyup="if (/\D/.test(this.value)) { this.value = val; }" ></td> </tr> this is the code used for sending the items to the email but only the items in the check boxes show up foreach ($_POST['MLIS'] as $item){ $items .= $item ."\n"; the items are stored in the php variable $items |
You really have not provided enough of your code. However, from what you did post the text box is not stored in the MLIS array.
|
Quote:
<form name"MUD LAB INVENTORY SYSTEM" method="post" action="index.php"> <tr> <td><input type="checkbox" name="MLIS[]" value="Notepads" />Notepads</td> <td><input type="text" name="quantity_1" size="1" maxlength="2" onkeydown="val = this.value;" onkeyup="if (/\D/.test(this.value)) { this.value = val; }" ></td> </tr> <tr> <td><input type="checkbox" name="MLIS[]" value="Envelopes" />Envelopes</td> <td> <input type="text" name="quantity_2" size="1" maxlength="2" onkeydown="val = this.value;" onkeyup="if (/\D/.test(this.value)) { this.value = val; }"></td> </tr> <tr> <td><input type="checkbox" name="MLIS[]" value="Staples" />Staples</td> <td><input type="text" name="quantity_3" size="1" maxlength="2"onkeydown="val = this.value;" onkeyup="if (/\D/.test(this.value)) { this.value = val; }"></td> </tr> <tr> <td><input type="checkbox" name="MLIS[]" value="Post It Notes" />Post It Notes</td> <td><input type="text" name="quantity_4" size="1" maxlength="2" onkeydown="val = this.value;" onkeyup="if (/\D/.test(this.value)) { this.value = val; }"></td> </tr> <tr> <td><input type="checkbox" name="MLIS[]" value="Red Ink Pens" />Red Ink Pens</td> <td><input type="text" name="quantity_5" size="1" maxlength="2" onkeydown="val = this.value;" onkeyup="if (/\D/.test(this.value)) { this.value = val; }"> </td> </tr> <tr> <td><input type="checkbox" name="MLIS[]" value="Black Ink Pens" />Black Ink Pens</td> <td> <input type="text" name="quantity_6"size="1" maxlength="2" onkeydown="val = this.value;" onkeyup="if (/\D/.test(this.value)) { this.value = val; }"> </td> </tr> <tr> <td><input type="checkbox" name="MLIS[]" value="Red Ink Pens" />Blue Ink Pens</td> <td><input type="text" name="quantity_7" size="1" maxlength="2" onkeydown="val = this.value;" onkeyup="if (/\D/.test(this.value)) { this.value = val; }"></td> </tr> <tr> <td><input type="submit" value= "Send"></td> </tr> </form> </table> <?php } else{ error_reporting(0); $email="somebody@somewhere.com" $subject="Subject"; $body= "Dear Joyce,\n\nBelow is a list of all the items that are currently needed at the Mud Lab:"; $items=""; $footer = "Regards"." "."staff_member"; $staff_member = "Staff Member"; foreach ($_POST['MLIS'] as $item){ $items .= $item ."\n"; } $msg_body = $body."\n\n$items.\n\n".$footer; $recipient = "somebody@somewhere.com"; $from = stripslashes($email); $subject = stripslashes("Test Mail"); $msg = "Message from: $from\n\n".stripslashes($msg_body); $header = 'From: "somebody@somewhere.com"'."\r\n".'Reply-To: $staff_member'."\r\n". 'X-Mailer: PHP/' . phpversion(); if (mail($recipient, $subject, $msg, $header)){ echo ("<b>Message Sent To:</b> $recipient"); } else echo "Message failed"; } |
Homework?
|
Quote:
|
Your PHP code is only processing the MLIS array which only contains check box values. You need to get the data from the text boxes. It is possible to use an array for the text boxes but the lengths will be different i.e. MLIS vs textbox.
|
Quote:
now I get it.I used an array for the text boxes used another foreach statement with the required variables for the text boxes and it worked.Thanks man |
the logic seems right but it does not work
I am trying to write a block of code in php that will echo an error if the value entered in a text box is not an integer.The logic behind the code seems correct but when the form is processed it returns the erro message even if the value entered is an int.
SAMPLE CODE =========== if (($_POST['quantityBox'.$i] != "") && (! is_int ($_POST['quantityBox'.$i]))) { $errorMessage[] = "only numbers are allowed in the quantity box!"; } |
first of all it might be better to replace
Code:
($_POST['quantityBox'.$i] != "") Code:
(isset(($_POST['quantityBox'.$i])) is_numeric() instead of is_int() |
Quote:
is_numberic () was the correct funtion to use. THANKS! |
yw ;)
p.s. the first one i mentioned the ($_POST['quantityBox'.$i] != "") vs (isset(($_POST['quantityBox'.$i])) at first blush may not seem to be any different but especially when dealing with checkboxes the variable is only null until its been used once then it becomes an array of nulls if nothing is selected, isset() should be able to deal with that but if !="" will not. |
All times are GMT -5. The time now is 01:05 PM. |