Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jun 2005
    Posts
    83
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Adding form field in PHP

    I'm trying to ad some additional fields to a PHP form. I can't get the field to come through on the form.

    FROM html page:
    Code:
    <tr><td>Site Name:</td><td><input type="text" name="name" size="25" /></td></tr>
    <tr><td>Site URL:</td><td><input type="text" name="siteurl" size="25" /></td></tr>
    <tr><td>Email address:</td><td><input type="text" name="email" size="25" /></td></tr>
    From the php form:
    Code:
    $messageproper =
    
    	"This message was sent from:\n" .
    	"$http_referrer\n" .
    	"------------------------------------------------------------\n" .
    	"Site Name: $name\n" .
                 "Site URL: $siteurl\n" .	
                 "Email of sender: $email\n" .
    	"------------------------- COMMENTS -------------------------\n\n" .
    	$comments .
    	"\n\n------------------------------------------------------------\n" ;
    
    mail($mailto, $subject, $messageproper,
    	"From: \"$name\" <$email>" . $headersep . "Reply-To: \"$name\" <$email>" . $headersep . "X-Mailer: chfeedback.php 2.08" );
    header( "Location: $thankyouurl" );
    exit ;
    The email comes through with the Site URL field blank as follows:
    Site Name: buzzzzzzzzzz
    Site URL:
    Email of sender: abc@xxxxxxxx.ca
    ------------------------- COMMENTS -------------------------

    kdoodf kdkkfdpkf pkdpkfpfkzdk/zdp

    Can someone point me to what I am missing in the code to make the addition field "siteurl" work? Thank You.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Check your log files, chances are you have an undefined variable being called.
    Nothing is incorrect with your code, just the way you are accessing it. PHP uses superglobals and more and more hosts are leaving the register_globals directive disabled (which is good, php 6 removes them completely and I'm happy about that ).
    The other variables are likely extracted elsewhere, using either a $_REQUEST/_POST/_GET array indexed with the field name. So, to retrieve your data you would use $_POST['siteurl'] or $_GET['siteurl'] depending on if your form's method is get or post.
    That is a likely cause for your problem. Try that first (remember to clean your variables out using addslashes and htmlspecialchars or htmlentities before using), and see if that works for you. Otherwise I don't see anything wrong with what you have.
    On a side note, I didn't think you could use "name="name"" as a named field item, could swear that caught me up once... or maybe that was id? Meh, whatever lol
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •