Jump to content

HELP, How to display the form entries in a textarea field


Recommended Posts

hi im trying to display the form entities in the textarea field so they can be sent to the user in an email, but its not working properly it prints out the variable $idName instead of its value?? any help would be greatly appricated ive been stuck on this bit of ages

 

<?php
function display_output_page()
{
   $idName = trim($_REQUEST['username']);
   $firstName = trim($_REQUEST['firstname']);
   $Surname = trim($_REQUEST['surname']);
   $Address = trim($_REQUEST['address']);
   $Email = trim($_REQUEST['email']);
   $Phone = trim($_REQUEST['phone']);
   $Fitness = isset($_REQUEST['fitness']) ? $_REQUEST['fitness'] : '';
   $goGym = isset($_REQUEST['gogym']) ? $_REQUEST['gogym'] : '';
   $whyGym = isset($_REQUEST['whyGym']) ? $_REQUEST['whyGym']: array();
?>
   <html>
   <head><title>Form Results</title></head>
   <body>
   <h1>Form Results</h1>
   <form action='mailto:$Email?subject=user comments' method='post'enctype='text/plain'>
<textarea name='Topic' rows=15 cols=90>

idName: ". $idName\n;
Firstname: ". $_POST["firstname"]\n;
Surname: ". $_POST["surname"]\n;
Address: ". $_POST["address"]\n;
Email: ". $_POST["email"]\n;
Phone no.: ". $_POST["phone"]\n;
Your fitness level: ". $_POST["fitness"]\n;
How often do you go to the gym: ". $_POST["goGym"]\n;
Why do you go to the Gym: ". $_POST["whyGym"];
</textarea></br>
<input type='submit' value='Send Thru Email'>
</form>
</body>
</html>
<?php
}
?>

And please try not to use $_REQUEST global as it has known security issues that could potentially open your site to hackers..

 

Your code should look like this:-


idName: <?php echo $idName; ?><br>
Firstname: <?php echo  $_POST["firstname"]; ?><br>
Surname: <?php echo $_POST["surname"]; ?><br>
Address: <?php echo $_POST["address"]; ?><br>
Email: <?php echo $_POST["email"]; ?><br>
Phone no: <?php echo $_POST["phone"]; ?><br>
Your fitness level: <?php echo $_POST["fitness"]; ?><br>
How often do you go to the gym: <?php echo $_POST["goGym"]; ?><br>
Why do you go to the Gym: <?php echo $_POST["whyGym"]; ?><br>

 

Of course you are 'presuming' that these values are set, and that the form is being filled out by a human; pop a captcha in to sort that issue out, and as you are using $_POST data directly into an email, please sanitise the data before using it.

 

I just noticed that this entire form is being created within a function; all good, but functions are best used when they are RETURNing data, then at least you can include error handlers, and use boolean values to their full potentials, it's all well and good programming something to work and send an email etc, etc, but it's even better to include error handlers in there so that you can inform yourself (during development) of any erroneous eventualities so that you can 1) keep traffic on your site 2) not revel anything about your site to the end user.

 

Hope that makes sense.

 

Rw

Hi rwwd, thanks for your help ive encountered another two problems tho,on the output below the part where it says how often do you go to the gym its printing array, when its should print often or one of the other choices and when i got to email the answers form to myself it doesnt use the email entered instead it prints out $Email in the address bar any ideas(<form action='mailto:'$Email'?subject=user comments' method='post'enctype='text/plain'>)this is the code im using to send the email

 

idName: qwe<br>

Firstname: qwe<br>

Surname: asd<br>

Address: asd<br>

Email: example@hotmail.ie<br>

Phone no: 124-456-1234<br>

Your fitness level: Above Average<br>

How often do you go to the gym: once<br>

Why do you go to the Gym: Array<br>

 

For the array problem, use this line.

Why do you go to the Gym: <?php echo implode(',',$_POST["whyGym"]); ?><br>

 

For the email problem, use this line:

<form action='mailto:<?php echo $Email; ?>?subject=user comments' method='post'enctype='text/plain'>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.