Page 1 of 1

newbie needing form help

Posted: Fri Nov 07, 2008 10:41 am
by nealhendes
Moved to PHP - Code forum and added BBcode tags for easier reading of code. Neal, welcome, but please learn how to format your posts for ease of reading by people who want to help you. Thanks.

Hi guys,

ive been slogging this for about 3 hours and just ant get it to work. I was hoping someone could tell me why.
The actual form itself works the bit I'm having trouble with is the end. I want it to send the form to my email address and display the info. I cant seem to get it to display all the info collected. At most it will display the title and firstname but not any other field.

Below is the code.

------------------------------------

Code: Select all

 
<?php
  $title = $_REQUEST['title'] ;
  $firstname = $_REQUEST['firstname'] ;
  $surname = $_REQUEST['surname'] ;
  $address = $_REQUEST['address'] ;
  $postcode = $_REQUEST['postcode'] ;
  $telephone = $_REQUEST['telephone'] ;
  $email = $_REQUEST['email'] ;
  $companyname = $_REQUEST['companyname'] ;
  
 
  if (!isset($_REQUEST['email'])) {
    header( "Location: http://www.purplecresscatering.com/contact.html" );
  }
  elseif (empty($email)) {
    ?>
 
    <html>
    <head><title>Error</title></head>
    <body>
    <h1>Error</h1>
    <p>
    Oops, it appears you forgot to enter either your
    email address. Please press the BACK
    button in your browser and try again.
    </p>
    </body>
    </html>
 
    <?php
  }
  else {
    mail( "nealhendes@hotmail.com", "Contact Form Results", $title, $firstname, $surname, 
$address, $postcode, $telephone, $email, $companyname "From: $email" );
    header( "Location: http://www.purplecresscatering.com" );
  }
?>
 
------------------------------------------

Thanks in advance and i'm sorry if this is a complete novice question. Only started learning today.

Neal.

Re: newbie needing form help

Posted: Fri Nov 07, 2008 2:34 pm
by JAB Creations
Hi and welcome to the General Discussion forum where we don't discuss computer code. :evil:

Moving along I never use $_REQUEST, never worked for me whatsoever. Stick to $_POST and $_GET and if that doesn't work look at the error messages and if there are none read it like a computer.

Re: newbie needing form help

Posted: Fri Nov 07, 2008 3:27 pm
by califdon
Submitting data from a web form requires two actions: (1) display an HTML form for the user to complete; and (2) submit the form data to be processed (entered in a database or emailed or something). The two actions can be done either in two different scripts or, with some conditional programming to determine whether data is being submitted or not, in one script. In either case, the data can be sent by either of two methods: POST or GET. POST is perhaps the most commonly used; it is better suited to larger amounts of data and it avoids exposing the passed data in the URL of the second script (it's the GET method being used when you see something like this: http://xyz.com/myaction.php?id=12345&mode=new).

It looks like you're probably using the POST method and 2 scripts. But we can't tell, because you've only shown us the second part, the processing script, and you're using the $_REQUEST[] array, which combines both $_GET[] and $_POST[] arrays. As Jab Creations just said, it's better to use the specific arrays rather than $_REQUEST[], if only to make it clearer what your script is doing. Now, why are you only getting some of your data? The way to answer this (other than showing us the script that generates the form and thus the data) is to echo the values of the variables temporarily, so you can see what you're getting and not getting. An easy way to do this is to add the following line right after the opening <?php line:

Code: Select all

print_r($_POST[]);
This will print on your web page the values of all the elements of the $_POST[] array. If some of your desired values are not present, you will need to review your HTML form code to insure that you have all the name= values of your form input elements correct. You may even see the problem as different spellings of the names when you see the actual contents of the $_POST[] array.