/    Sign up×
Community /Pin to ProfileBookmark

Problems passing variables from form

I’ve got “form to mail” script that I can seem to work. I can’t seem to grab the variables after submitted. Also I want to be able to put the variable values into the message of the email being sent. That should be easy once I can get the values of the variables being passed. Any help is greatly appriciated.

[code=html]
<FORM METHOD=”POST” ACTION=”test2.php” ENCTYPE=”text/plain” NAME=”form2″>
Last Name: <INPUT TYPE=”TEXT” NAME=”last” SIZE=”15″>
First Name: <INPUT TYPE=”TEXT” NAME=”first” SIZE=”10″>
Middle Initial <INPUT TYPE=”TEXT” NAME=”mi” SIZE=”1″ MAXLENGTH=1>
Clock Number <BR><INPUT TYPE=”TEXT” NAME=”clock” SIZE=5 MAXLENGTH=5
ONKEYPRESS=”if ((event.keyCode < 48) ||
(event.keyCode > 57)) event.returnValue = false;”>
<INPUT TYPE=”hidden” NAME=”class” Value=”Systems Engineering Class #1″>
<INPUT TYPE=”hidden” NAME=”dt” Value=”January 22, 2006: 1PM – 3PM”>
<INPUT TYPE=”hidden” NAME=”place” Value=”Cleveland Conference Room”>
<INPUT TYPE=”SUBMIT” VALUE=”Submit” onClick=”return validateForm2()”>
</FORM>
[/code]

[code=php]<?php
$last = $_POST[‘last’];
$first = $_POST[‘first’];
$mi = $_POST[‘mi’];
$clock = $_POST[‘clock’];
$class = $_POST[‘class’];
$dt = $_POST[‘dt’];
$place = $_POST[‘place’];

$to = ‘[email protected]’;
$subject = ‘test’;
$message =’$place’; // testing purposes

if(@mail($to, $subject, $message))
{
print ‘<p>Mail sent OK! $place</p>’;
}
else
{
print ‘<p>Error sending the mail!</p>’;
}
?> [/code]

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJan 25.2006 — [code=php]
<?php
$message = ""; // initialize message
// Add each $_POST value to message:
foreach($_POST as $key => $value)
{
$message .= "$key: $valuen";
}
$to = '[email protected]';
$subject = 'test';
if(@mail($to, $subject, $message))
{
print '<p>Mail sent OK! $place</p>';

}
else
{
print '<p>Error sending the mail!</p>';
}

?>
[/code]
Copy linkTweet thisAlerts:
@asianmikeauthorJan 25.2006 — Still not working. I still get a blank email. ?
Copy linkTweet thisAlerts:
@NogDogJan 25.2006 — Time to do some debugging, then:
[code=php]
$message = ""; // initialize message
// Add each $_POST value to message:
foreach($_POST as $key => $value)
{
$message .= "$key: $valuen";
}
if(trim($message) == "")
{
echo "<p>ERROR: no data populated from $_POST</p>n";
echo "<pre>DEBUG:n";
print_r($_POST);
echo "</pre>n";
}
[/code]
Copy linkTweet thisAlerts:
@asianmikeauthorJan 25.2006 — I get the following:

ERROR: no data populated from Array

DEBUG:

Array

(

)

Mail sent OK!
Copy linkTweet thisAlerts:
@NogDogJan 25.2006 — So no post data was received from the form page. My next suspect then would be the validateForm2() JavaScript function you're calling from the onclick event in the submit button. For a quick test, try deleting the onclick attribute from the submit tag and see if it works. If it does, then you know it's time to ask the JavaScript gurus.
Copy linkTweet thisAlerts:
@asianmikeauthorJan 25.2006 — Hey!! I think it's working now. I deleted "ENCTYPE="text/plain"" from the form part. It seems ok now. Thanks for all your help!
×

Success!

Help @asianmike spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...