Web Hosting Talk







View Full Version : I don't know php!


CPQIS
03-07-2004, 03:34 PM
Hey I made this form, and please know that I have no idea what I'm doing when it comes to php!!!

I didn't know if the mail to part of it goes before or after the form, so I put it on both... When I click submit, it sends to my email, but the form is not sent. Also, how would I make it so it says who it's from? I mean, like for the email field, how do I make it show up as from "email field"... Did I loose you?

Here's the form I have. If you respond, please respond in detail and try not to confuse me with all the php terms!!!

<?php

if ($_POST['form']) { //process the data


$from = $_POST['Free Signup'].' <'.$_POST['email'].'>';
mail ("coryp@cpqservices.com",$subject, $message, "From: $from");

?>
Your website will be activated within 48hrs. Your account details will be mailed to the email address you provided.
<?php

} else { //get the data

?></p><?php echo $PHP_SELF; ?>
<form method="POST">
<div align="left">
<p>
<input type="hidden" name="form" value="1">
<br>
<span class="style2">*Full Name:</span>
<input type="text" name="textfield">

*Email Address:
<input type="text" name="textfield2">
</p>
<p>*Username:
<input type="text" name="textfield3">
*Password:
<input type="password" name="textfield4">
</p>
<p>*Website Name:
<input name="textfield5" type="text" value=".cpqservices.com">
Phone Number:
<input type="text" name="textfield6">
</p>
<p>How did you hear of us?
<select name="select">
<option>Search Engine</option>
<option>Forum</option>
<option>A friend</option>
<option>I followed a link</option>
<option>Other</option>
</select>
<br>
</p>
</div>
<button type="submit" name="submit">SIGN UP! </button>
</form><?php

if ($_POST['form']) { //process the data


$from = $_POST['Free Signup'].' <'.$_POST['email'].'>';
mail ("coryp@cpqservices.com",$subject, $message, "From: $from");

?>
Your website will be activated within 48hrs. Your account details will be mailed to the email address you provided.
<?php

} else { //get the data

?>

It's for free hosting, and I think someone sent me a signup, and if your reading this, I didn't reply because of form problems!

Informity
03-07-2004, 04:33 PM
<?php

if (isset($_POST)) { //process the data

$subject = "Free Signup" . $_POST['textfield2'];
$message = "Information Posted:\n\n Full Name: " . $_POST['textfield'] . "\nEmail Address: " . $_POST['textfield2'] . "\nPassword: " . $_POST['textfield4'] . "\nWebsite Name: " . $_POST['textfield5'] . "\nPhone #" . $_POST['textfield6'] . "\nHeard of us from: " . $_POST['select'];

mail ("coryp@cpqservices.com", $subject, $message);

?>
Your website will be activated within 48hrs. Your account details will be mailed to the email address you provided.
<?php

} else { //get the data

?>
<form method="POST" action="<?php echo $PHP_SELF; ?>">
<div align="left">
<p>
<br>
<span class="style2">*Full Name:</span>
<input type="text" name="textfield">

*Email Address:
<input type="text" name="textfield2">
</p>
<p>*Username:
<input type="text" name="textfield3">
*Password:
<input type="password" name="textfield4">
</p>
<p>*Website Name:
<input name="textfield5" type="text" value=".cpqservices.com">
Phone Number:
<input type="text" name="textfield6">
</p>
<p>How did you hear of us?
<select name="select">
<option value="Search Engine">Search Engine</option>
<option value="Forum">Forum</option>
<option value="A friend">A friend</option>
<option value="Followed a link">I followed a link</option>
<option value="Other">Other</option>
</select>
<br>
</p>
</div>
<input type="submit" value="SIGN UP!" />
</form>



That *should* work.

I think you need to read up on HTML forms before I can explain how it works.

Basically each form element you need the info from has a "name" property. When the form is submitted to a php script (in this case it's self), you can get access to the information posted using:

$_POST['name']

where name is the name of the form element.

CPQIS
03-07-2004, 09:55 PM
I get this error with that form -

Parse error: parse error in /home/cory779/public_html/freesignup1.php on line 74

Informity
03-07-2004, 11:11 PM
ahh, add

<?
}
?>

to the end of the script

CPQIS
03-08-2004, 10:49 PM
When I go to the page the form is not visible. It just goes straight to "Thank you for your signup..." and send me an email with everything blank.

?

Umbongo
03-08-2004, 11:48 PM
change:
if (isset($_POST)) {
to:
if (!empty($_POST)) {

CPQIS
03-09-2004, 12:24 AM
How would I make it so it check if they input something in the fields, and if not, sends them to an error page?

azurehost
03-09-2004, 02:14 PM
<?php
if(!$_POST['textfield']) {

echo "error msg goes here.";

}

?>

CPQIS
03-09-2004, 10:25 PM
Where would I add that?

azurehost
03-10-2004, 03:20 PM
Anywhere after the :

if (isset($_POST))


Code.

CPQIS
03-10-2004, 09:44 PM
<?php
if(!$_POST['textfield']) {

echo "error msg goes here.";

}

?>


That's not working for me. When I don't fill out that field, all it says is "error message goes here. Your website will be activated within 48hrs. Your account details will be mailed to the email address you provided. " and sends to my email anyway.

Here's what I got:


<?php

if (!empty($_POST)) { //process the data

if(!$_POST['Email Address']) {

echo "error msg goes here.";


}


$subject = "Free Signup" . $_POST['textfield2'];
$message = "Information Posted:\n\n Full Name: " . $_POST['Full Name'] . "\nEmail Address: " . $_POST['Email Address'] . "\nPassword: " . $_POST['Password'] . "\nWebsite Name: " . $_POST['Website Name'] . "\nFollowed by: " . $_POST['Followed by'] . "\nPhone #" . $_POST['Phone #'] . "\nHeard of us from: " . $_POST['Heard from us by'];

mail ("coryp@cpqservices.com", $subject, $message);

?>
Your website will be activated within 48hrs. Your account details will be mailed to the email address you provided.
<?php

} else { //get the data

?>
<form method="POST" action="<?php echo $PHP_SELF; ?>">
<div align="left">
<p>
<br>
<span class="style2">*Full Name:</span>
<input type="text" name="Full Name">

*Email Address:
<input type="text" name="Email Address">
</p>
<p>*Username:
<input type="text" name="Username">
*Password:
<input type="password" name="Password">
</p>
<p>*Website Name:
<input name="Website Name" type="text">
<select name="Followed by">
<option>.cpqservices.com</option>
</select>
</p>
<p>Phone Number:
<input type="text" name="Phone #">
</p>
<p>How did you hear of us?
<select name="Heard from us by:">
<option value="Search Engine">Search Engine</option>
<option value="Forum">Forum</option>
<option value="A friend">A friend</option>
<option value="Followed a link">I followed a link</option>
<option value="Other">Other</option>
</select>
<br>
</p>
</div>
<input type="submit" value="SIGN UP!" />
</form>
<?
}
?>