LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-21-2009, 03:31 PM   #1
3vra
Member
 
Registered: Dec 2008
Distribution: ubuntu
Posts: 51
Blog Entries: 1

Rep: Reputation: 16
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
 
Old 01-21-2009, 03:57 PM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,710

Rep: Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972
Quote:
Originally Posted by 3vra View Post
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
Don't have the variable...you didn't attach it. Check out the PHP manual at http://us.php.net/explode, specifically, the explode command.
 
Old 01-22-2009, 08:23 AM   #3
3vra
Member
 
Registered: Dec 2008
Distribution: ubuntu
Posts: 51

Original Poster
Blog Entries: 1

Rep: Reputation: 16
Variable I left out (item)

foreach ($_POST['MLIS'] as $item){
$items .= $item." ";

}

here is the copy of the variable I left out
 
Old 01-22-2009, 10:30 AM   #4
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 116Reputation: 116
Quote:
Originally Posted by 3vra View Post
foreach ($_POST['MLIS'] as $item){
$items .= $item." ";

}

here is the copy of the variable I left out
$items .= $item."\n";
 
Old 01-23-2009, 02:20 PM   #5
3vra
Member
 
Registered: Dec 2008
Distribution: ubuntu
Posts: 51

Original Poster
Blog Entries: 1

Rep: Reputation: 16
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
 
Old 01-23-2009, 03:15 PM   #6
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,760

Rep: Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931
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.
 
Old 01-23-2009, 04:32 PM   #7
3vra
Member
 
Registered: Dec 2008
Distribution: ubuntu
Posts: 51

Original Poster
Blog Entries: 1

Rep: Reputation: 16
Quote:
Originally Posted by michaelk View Post
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.

<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";
}

Last edited by 3vra; 01-23-2009 at 04:40 PM.
 
Old 01-23-2009, 08:44 PM   #8
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,760

Rep: Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931
Homework?
 
Old 01-26-2009, 08:56 AM   #9
3vra
Member
 
Registered: Dec 2008
Distribution: ubuntu
Posts: 51

Original Poster
Blog Entries: 1

Rep: Reputation: 16
Quote:
Originally Posted by michaelk View Post
Homework?
No.I'm just learning HTML and PHP and trying things out.I just need an explanation on what's going on so I can understand why I am not getting the results I want.
 
Old 01-26-2009, 10:33 AM   #10
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,760

Rep: Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931
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.
 
Old 01-26-2009, 11:08 AM   #11
3vra
Member
 
Registered: Dec 2008
Distribution: ubuntu
Posts: 51

Original Poster
Blog Entries: 1

Rep: Reputation: 16
Quote:
Originally Posted by michaelk View Post
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.
\

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
 
Old 02-12-2009, 12:52 PM   #12
3vra
Member
 
Registered: Dec 2008
Distribution: ubuntu
Posts: 51

Original Poster
Blog Entries: 1

Rep: Reputation: 16
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!";
}
 
Old 02-12-2009, 01:41 PM   #13
frieza
Senior Member
 
Registered: Feb 2002
Location: harvard, il
Distribution: Ubuntu 11.4,DD-WRT micro plus ssh,lfs-6.6,Fedora 15,Fedora 16
Posts: 3,233

Rep: Reputation: 406Reputation: 406Reputation: 406Reputation: 406Reputation: 406
first of all it might be better to replace
Code:
($_POST['quantityBox'.$i] != "")
with
Code:
(isset(($_POST['quantityBox'.$i]))
second, form input always returns as a string, try

is_numeric() instead of is_int()
 
Old 02-12-2009, 01:50 PM   #14
3vra
Member
 
Registered: Dec 2008
Distribution: ubuntu
Posts: 51

Original Poster
Blog Entries: 1

Rep: Reputation: 16
Quote:
Originally Posted by frieza View Post
first of all it might be better to replace
Code:
($_POST['quantityBox'.$i] != "")
with
Code:
(isset(($_POST['quantityBox'.$i]))
second, form input always returns as a string, try

is_numeric() instead of is_int()

is_numberic () was the correct funtion to use. THANKS!
 
Old 02-12-2009, 02:24 PM   #15
frieza
Senior Member
 
Registered: Feb 2002
Location: harvard, il
Distribution: Ubuntu 11.4,DD-WRT micro plus ssh,lfs-6.6,Fedora 15,Fedora 16
Posts: 3,233

Rep: Reputation: 406Reputation: 406Reputation: 406Reputation: 406Reputation: 406
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
master - details forms with php htamayo Programming 1 04-09-2008 04:48 PM
PHP having issues while accepting variables from forms ashesh0326 Programming 4 05-07-2007 07:01 AM
LXer: Html Forms and PHP LXer Syndicated Linux News 0 01-09-2007 01:33 AM
PHP & Apache - php files not processing aolong Linux - General 1 12-17-2006 03:09 AM
passing an array from html-forms to php prabhatsoni Linux - Software 2 06-04-2005 12:11 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:26 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration