PHP Simplicity Forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

Some of SFU features: Universal password protection, notification of uploads and logging just to name few.

Author Topic: Add a contact field to the form...  (Read 9621 times)

0 Members and 1 Guest are viewing this topic.

eakucera00

  • Guest
Add a contact field to the form...
« on: August 15, 2005, 08:41:04 PM »

i would like to add a field that forces the user to enter there e-mail address or there phone number or name..  and when submitted, the response e-mail would contain the user's contact info they provided.  This would be helpful to identify who uploaded what files.

any help would be greatly appreciated.  your welcome to e-mail me directly.

thanks,

Ernie
Logged

Saleh

  • Administrator
  • Full Member
  • *****
  • Offline Offline
  • Posts: 222
    • View Profile
    • PHP Simplicity
Re: Add a contact field to the form...
« Reply #1 on: August 19, 2005, 06:36:03 AM »

open functions.php and look for:
Code: [Select]
function MailUploaded() {
   global $txt, $uploaded, $errors, $admin_email, $URL;

  //we put an introduction and the IP address of the user who attempted to upload
   $message = $txt['mail']['head'];
   $message.= "$_SERVER[REMOTE_ADDR]\n\n";

replace it with:
Code: [Select]
function MailUploaded($extra_message = null) {
   global $txt, $uploaded, $errors, $admin_email, $URL;

  //we put an introduction and the IP address of the user who attempted to upload
   $message = $txt['mail']['head'];
   $message.= "$_SERVER[REMOTE_ADDR]\n$extra_message\n\n";   


also look for (in the same file):
Code: [Select]
//start the loop ..
   for ($i = 0; $i < $num_files; $i++) {
      $form .= '
            <input type="file" name="SFUfile[]" size="20" '.$disabled.'/><br />';
   }

add after:
Code: [Select]
$form.= '<br />Email: <input type="text" name="email" /><br />';

in upload.php, look for:
Code: [Select]
if (isset($_POST['SFUsubmit'])) {
add after:
Code: [Select]
   if (!isset($_POST['email']) || !preg_match('~^[_0-9a-z\-\.]+@[_0-9a-z\-\.]+\.[_0-9a-z\-\.]+$~i',$_POST['email'])) {
      echo 'You did not enter your email!';
      html_footer();
      exit;
   }

also look for:
Code: [Select]
   if ($notify_admin == true)
      MailUploaded();

replace with:
Code: [Select]
   if ($notify_admin == true)
      MailUploaded($_POST['email']);

this should do it :)
« Last Edit: November 18, 2010, 08:35:40 AM by Saleh »
Logged

We don't need a reason to help people

Ernie

  • Guest
Re: Add a contact field to the form...
« Reply #2 on: August 21, 2005, 12:40:41 PM »

   if (!isset($_POST['email']) || !preg_match('^[a-z0-9\._-]+@+[a-z0-9\._-]+\.+[a-z]{2,4}$',$_POST['email'])) {
      echo 'You did not enter your email!';
      html_footer();
      exit;
   }



everytime i try entering my e-mail address and submit it always states that i "did not enter my e-mail address".  I think something is wrong with the validation.  other than that it looks like it should work.

thanks for your help again.
Logged

Saleh

  • Administrator
  • Full Member
  • *****
  • Offline Offline
  • Posts: 222
    • View Profile
    • PHP Simplicity
Re: Add a contact field to the form...
« Reply #3 on: August 22, 2005, 03:38:16 AM »

replace:
Code: [Select]
if (!isset($_POST['email']) || !preg_match('^[a-z0-9\._-]+@+[a-z0-9\._-]+\.+[a-z]{2,4}$',$_POST['email'])) {with:
Code: [Select]
if (!isset($_POST['email']) || !preg_match('~^[_0-9a-z\-\.]+@[_0-9a-z\-\.]+\.[_0-9a-z\-\.]+$~i',$_POST['email'])) {
as you said, the validation regexp was incorrect, sorry :(
Logged

We don't need a reason to help people

chad

  • Guest
Re: Add a contact field to the form...
« Reply #4 on: January 04, 2006, 11:01:54 AM »

I have been trying to do this on my own and I realized you had a forum and I found exactly what I needed! This helped a lot, but I am still having trouble with the email validation. I replaced the validation code as you advised above and It still states that i have not entered an email address.
Logged

Saleh

  • Administrator
  • Full Member
  • *****
  • Offline Offline
  • Posts: 222
    • View Profile
    • PHP Simplicity
Re: Add a contact field to the form...
« Reply #5 on: January 18, 2006, 08:09:44 AM »

I am not sure why it's not working for you, but it should!
anyway, you could replace the validation with a simple one like:
Code: [Select]
if (!isset($_POST['email']) || trim($_POST['email']) == '') {
Logged

We don't need a reason to help people

justin

  • Guest
Re: Add a contact field to the form...
« Reply #6 on: April 02, 2006, 12:36:06 PM »

hey i have did it to but the results ar

http://www.server255.byethost9.com/uper/upload.php

not good  can you help me :D
Logged

Saleh

  • Administrator
  • Full Member
  • *****
  • Offline Offline
  • Posts: 222
    • View Profile
    • PHP Simplicity
Re: Add a contact field to the form...
« Reply #7 on: April 03, 2006, 11:36:50 AM »

you put <input type="text" name="email" /> in the wrong place, man :)

open functions.php and look for:
Code: [Select]
//start the loop ..
   for ($i = 0; $i < $num_files; $i++) {
      $form .= '
            <input type="file" name="SFUfile[]" size="20" '.$disabled.'/><br />';
   }

and then after it add:
Code: [Select]
$form.= '<br />Email: <input type="text" name="email" /><br />';
if you tried this and you are still having trouble, you could email me the functions.php file and I will modify it for you :)
« Last Edit: April 04, 2006, 06:37:23 PM by Saleh »
Logged

We don't need a reason to help people

justin

  • Newbie
  • *
  • Offline Offline
  • Posts: 2
    • View Profile
Re: Add a contact field to the form...
« Reply #8 on: April 04, 2006, 03:14:52 AM »

no it dont works it was the same that i did before  :( :(

i send you a personel message with in zip format my funtion.php


grtzz justin
Logged

Saleh

  • Administrator
  • Full Member
  • *****
  • Offline Offline
  • Posts: 222
    • View Profile
    • PHP Simplicity
Re: Add a contact field to the form...
« Reply #9 on: April 04, 2006, 06:37:12 PM »

oppss!
my bad! I found where the error is! it shouldn't be echo!
so instead change:
Code: [Select]
echo '<input type="text" name="email" /><br />';to:
Code: [Select]
$form.= '<br />Email: <input type="text" name="email" /><br />';
I tried this and it works fine :)
the problem that I forgot that echoing was the last part :(
Logged

We don't need a reason to help people

justin

  • Newbie
  • *
  • Offline Offline
  • Posts: 2
    • View Profile
Re: Add a contact field to the form...
« Reply #10 on: April 06, 2006, 03:42:28 AM »

thnx it works now

thanks for helping  ;D ;D ;D
Logged

Saleh

  • Administrator
  • Full Member
  • *****
  • Offline Offline
  • Posts: 222
    • View Profile
    • PHP Simplicity
Re: Add a contact field to the form...
« Reply #11 on: April 06, 2006, 06:25:41 PM »

no problem at all! :)
Logged

We don't need a reason to help people

snicka

  • Guest
Re: Add a contact field to the form...
« Reply #12 on: May 26, 2006, 12:41:23 PM »

I tried to get this to work and am having problems with it.

I would like to add 2 new text fields but I can't figure out how the text field data gets assigned to $extra_message. It would seem there is no code that assigns the data to this variable.

I tried following this post and made the same changes but it would not work. The email address did not get printed.

Any help is appreciated.
Logged

snicka

  • Guest
Re: Add a contact field to the form...
« Reply #13 on: May 26, 2006, 06:15:21 PM »

Well, I found my mistake and got it to work with 1 text field, but how can I add another?

Thanks for any help.
Logged

Saleh

  • Administrator
  • Full Member
  • *****
  • Offline Offline
  • Posts: 222
    • View Profile
    • PHP Simplicity
Re: Add a contact field to the form...
« Reply #14 on: May 27, 2006, 05:39:44 AM »

just add the new field like you did with the first one and then you can retraive its value with: $_POST['the_field_name']
Logged

We don't need a reason to help people

snicka

  • Guest
Re: Add a contact field to the form...
« Reply #15 on: May 27, 2006, 11:47:40 AM »

Thanks for your help.
Logged

Royal

  • Newbie
  • *
  • Offline Offline
  • Posts: 1
    • View Profile
Re: Add a contact field to the form...
« Reply #16 on: June 26, 2006, 11:44:05 AM »

SWEET SCRIPT! - Thanks

Can anyone describe the procedure for adding more fields I am a hacker more than a coder and having some issues.

Installed the email option but wanted to add a few other text fields and can not seem to get anything to work.

Thanks,
Royal
Logged

Saleh

  • Administrator
  • Full Member
  • *****
  • Offline Offline
  • Posts: 222
    • View Profile
    • PHP Simplicity
Re: Add a contact field to the form...
« Reply #17 on: June 27, 2006, 12:16:25 PM »

the previous posts should help.. what exactly you don't get to work?
Logged

We don't need a reason to help people

Dallas

  • Newbie
  • *
  • Offline Offline
  • Posts: 1
    • View Profile
Re: Add a contact field to the form...
« Reply #18 on: November 12, 2006, 05:19:17 PM »

Fantastic script, thanks! I've had fun playing with it all day.

I do have a question about adding additional fields. I'm not great with php - just starting to learn - but I've managed to add 3 additional fields but how do I get the info in all of them sent in the email notification ( I have this turned on )? Right now it sends 3 separate emails, one with each piece on info...so you can probably tell I've used this:

   if ($notify_admin == true)
      MailUploaded($_POST['email']);
   if ($notify_admin == true)
      MailUploaded($_POST['name']);
   if ($notify_admin == true)
     MailUploaded($_POST['additional_info']);

I know that's wrong but don't know the right way. Any help would be very much appreciated.

Thanks
Logged

Saleh

  • Administrator
  • Full Member
  • *****
  • Offline Offline
  • Posts: 222
    • View Profile
    • PHP Simplicity
Re: Add a contact field to the form...
« Reply #19 on: November 18, 2006, 01:01:27 PM »

Simply merge all those info into one variable and then send them:
$email_message $_POST['email'] . "\n" $_POST['name'] . "\n" $_POST['additional_info'];
if (
$notify_admin == true)
      
MailUploaded($email_message);


Hope that helps :)
Logged

We don't need a reason to help people

Bruce

  • Guest
Re: Add a contact field to the form...
« Reply #20 on: May 12, 2010, 12:37:17 PM »

I have been changing this around every way mentioned here and it has me lost I do not see the echo '<input type="text" name="email" /><br />'; anywhere to replace with $form.= '<br />Email: <input type="text" name="email" /><br />'; and I am lost. help would be appreciated. Bruce
Logged

bruce

  • Guest
Re: Add a contact field to the form...
« Reply #21 on: May 12, 2010, 05:02:21 PM »

the file is uploaded but i do not get the email name on the email I receive just the file name.
Logged

Hawk

  • Newbie
  • *
  • Offline Offline
  • Posts: 9
    • View Profile
Re: Add a contact field to the form...
« Reply #22 on: November 15, 2010, 12:30:21 PM »

Hi Folks!

I just found this great script and I think it's going to be very useful for my website.

I have done some modification based on information in this thread but I'm having a small issue that I hope someone can help me with (I know just enough about php to be dangerous.  :D ).

I've added some extra form fields (4) and would like all of them to be required but so far have only been able to make the last one required (email).
I get the error about not filling in the other 3 fields, but the file does successfully upload, but the file won't upload without the email field filled in.
I would like to file to fail the upload if any of the 4 fields are left empty.

Here's the data from the upload file:
Code: [Select]
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/*
Edit by me from this thread  http://www.phpsimplicity.com/forum/index.php?PHPSESSID=ed6443166758aae822456829323725f1&topic=61.0 
for extra form fields for email
*/
/*New edit*/
  #if (!isset($_POST['email']) || !preg_match('^[a-z0-9._-]+@+[a-z0-9._-]+.+[a-z]{2,4}$',$_POST['email'])) {
      if (!isset($_POST['fname']) || !preg_match('~^[a-zA-Z.-s]+$~i',$_POST['fname']))
        echo '<p align="'.$txt['align'].'"><span style="color:#800000"><b>Oops! You forgot to enter your First Name!</b></span>
        <br />Click your browser&rsquo;s &lsquo;Back&rsquo; button and try again<br /><br />';

      if (!isset($_POST['lname']) || !preg_match('~^[a-zA-Z.-s]+$~i',$_POST['lname']))
        echo '<p align="'.$txt['align'].'"><span style="color:#800000"><b>Oops! You forgot to enter your Last Name!</b></span>
        <br />Click your browser&rsquo;s &lsquo;Back&rsquo; button and try again<br /><br />';

      if (!isset($_POST['uname']) || !preg_match('~^[_0-9a-zA-Z-.s]+$~i',$_POST['uname']))
        echo '<p align="'.$txt['align'].'"><span style="color:#800000"><b>Oops! You forgot to enter your Forum Username!</b></span>
        <br />Click your browser&rsquo;s &lsquo;Back&rsquo; button and try again<br /><br />';

      if (!isset($_POST['email']) || !preg_match('~^[_0-9a-z-.]+@[_0-9a-z-.]+.[_0-9a-z-.]+$~i',$_POST['email'])) {
      echo '<p align="'.$txt['align'].'"><span style="color:#800000"><b>Oops! You forgot to enter your email!</b></span>
      <br />Click your browser&rsquo;s &lsquo;Back&rsquo; button and try again<br /><br />';
     
      exit;
   }
/*End Edit*/
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Here's the data from the functions file:
Code: [Select]
<tr>
      <td>
            <form method="post" enctype="multipart/form-data" action="'.$action.'" onsubmit="return preValidate();"/>
            <input type="hidden" name="MAX_FILE_SIZE" value="'.SFU_MAXSIZE * 1024 .'" />';
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/*
Edit by me from this thread  http://www.phpsimplicity.com/forum/index.php?PHPSESSID=ed6443166758aae822456829323725f1&topic=61.0 
for extra form fields for email
*/
/*New edit-Add*/

$form.= '<p class="bld"><span class="grn">First Name:</span><input type="text" name="fname" size="50" /></p>';
$form.= '<p class="bld"><span class="grn">Last Name:</span> <input type="text" name="lname" size="50" /></p>';
$form.= '<p class="bld"><span class="grn">Forum Username:</span> <input type="text" name="uname" size="50" /></p>';
$form.= '<p class="bld"><span class="grn">Email Address:</span> <span class="ital lt-blu">(Required)</span><input type="text" name="email" size="55" /></p>
<p class="add bld grn">Add your files:</p>';
/*End edit*/
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//start the loop ..
   for ($i = 0; $i < $num_files; $i++) {
      $form .= '
            <p><input type="file" name="SFUfile[]" size="47" '.$disabled.'/></p>';
   }

//close form..
   $form .='</td>
   </tr>';

I've also set it up to include the above information in the email the script sends. This works fine.

From the upload file:
Code: [Select]
$email_message = $_POST['email'] . " " . $_POST['fname'] . " " . $_POST['lname'] . " " . $_POST['uname'];
if ($notify_admin == true)
      MailUploaded($email_message);

I'm sure it's something simple but after 2 days of trying anything I could think of, I'm not finding the right answer.  ???

Thanks for any help!  :)

I've even been able to add an animated progress image as discussed in this thread:  http://www.phpsimplicity.com/forum/index.php/topic,194.0.html.
Feel free to test it and see the image.  ;)
 
« Last Edit: November 23, 2010, 05:29:08 PM by Hawk »
Logged
Hawk

Saleh

  • Administrator
  • Full Member
  • *****
  • Offline Offline
  • Posts: 222
    • View Profile
    • PHP Simplicity
Re: Add a contact field to the form...
« Reply #23 on: November 18, 2010, 08:28:13 AM »

Note that you have had exit; only on the email checking part.
The code should be like:
Code: [Select]
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/*
Edit by me from this thread  http://www.phpsimplicity.com/forum/index.php?PHPSESSID=ed6443166758aae822456829323725f1&topic=61.0
for extra form fields for email
*/
/*New edit*/
  #if (!isset($_POST['email']) || !preg_match('^[a-z0-9._-]+@+[a-z0-9._-]+.+[a-z]{2,4}$',$_POST['email'])) {
      if (!isset($_POST['fname']) || !preg_match('~^[a-zA-Z.-s]+$~i',$_POST['fname']))
  {
        echo '<p align="'.$txt['align'].'"><span style="color:#800000"><b>Oops! You forgot to enter your First Name!</b></span>
        <br />Click your browser&rsquo;s &lsquo;Back&rsquo; button and try again<br /><br />';

exit;
  }

      if (!isset($_POST['lname']) || !preg_match('~^[a-zA-Z.-s]+$~i',$_POST['lname']))
  {
        echo '<p align="'.$txt['align'].'"><span style="color:#800000"><b>Oops! You forgot to enter your Last Name!</b></span>
        <br />Click your browser&rsquo;s &lsquo;Back&rsquo; button and try again<br /><br />';

exit;
  }

      if (!isset($_POST['uname']) || !preg_match('~^[_0-9a-zA-Z-.s]+$~i',$_POST['uname']))
  {
        echo '<p align="'.$txt['align'].'"><span style="color:#800000"><b>Oops! You forgot to enter your Forum Username!</b></span>
        <br />Click your browser&rsquo;s &lsquo;Back&rsquo; button and try again<br /><br />';

exit;
  }

      if (!isset($_POST['email']) || !preg_match('~^[_0-9a-z-.]+@[_0-9a-z-.]+.[_0-9a-z-.]+$~i',$_POST['email']))
  {
      echo '<p align="'.$txt['align'].'"><span style="color:#800000"><b>Oops! You forgot to enter your email!</b></span>
      <br />Click your browser&rsquo;s &lsquo;Back&rsquo; button and try again<br /><br />';
     
      exit;
      }
/*End Edit*/
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

And that's the first time I've seen SFU modified and integrated in a such a nice way! Kudos :D
Logged

We don't need a reason to help people

Hawk

  • Newbie
  • *
  • Offline Offline
  • Posts: 9
    • View Profile
Re: Add a contact field to the form...
« Reply #24 on: November 18, 2010, 04:15:47 PM »

That did the trick. I knew it was something simple I was overlooking.  :D

Thanks for your help, and thank you for the kind words - but most of all, thank you for the great script.  ;D
Logged
Hawk

Saleh

  • Administrator
  • Full Member
  • *****
  • Offline Offline
  • Posts: 222
    • View Profile
    • PHP Simplicity
Re: Add a contact field to the form...
« Reply #25 on: November 18, 2010, 06:15:09 PM »

You are most welcome :)
Logged

We don't need a reason to help people

Hawk

  • Newbie
  • *
  • Offline Offline
  • Posts: 9
    • View Profile
Re: Add a contact field to the form...
« Reply #26 on: November 21, 2010, 08:23:52 AM »

I hate to bother you again, but how would I go about adding a message box and getting the message included in the email?

I can get the text area to show, but any message entered into the text box isn't included in the email.

Here's a link to the current test page:  http://paphalophagus.com/test/upload-page.htm

functions:
Code: [Select]
$form.= '
<p class="cent">First Name:<br /> <input type="text" name="fname" size="50" /></p>';
    $form.= '
<p class="cent">Last Name:<br /> <input type="text" name="lname" size="50" /></p>';
    $form.= '
<p class="cent">Forum Username:<br /> <input type="text" name="uname" size="50" /></p>';
    $form.= '
<p class="cent">Email Address:<br /> <input type="text" name="email" size="50" /></p>';
    $form.= '
<p class="cent">Add a Message:<br /> <textarea type="textarea" rows="6" cols="50" name="message" /></textarea></p>
<p class="cent add">Add your files: <span class="ital dk-yellow">(at least 1 File Required)</span></p>';

upload:
Code: [Select]
if (!isset($_POST['fname']) || !preg_match('~^[a-zA-Z.-s]+$~i',$_POST['fname']))
        echo '<p align="'.$txt['align'].'">';

      if (!isset($_POST['lname']) || !preg_match('~^[a-zA-Z.-s]+$~i',$_POST['lname']))
        echo '<p align="'.$txt['align'].'">';

      if (!isset($_POST['uname']) || !preg_match('~^[_0-9a-zA-Z-.s]+$~i',$_POST['uname']))
        echo '<p align="'.$txt['align'].'">';

      if (!isset($_POST['email']) || !preg_match('~^[_0-9a-z-.]+@[_0-9a-z-.]+.[_0-9a-z-.]+$~i',$_POST['email']))
      echo '<p align="'.$txt['align'].'">';
     
      if (!isset($_POST['message']) || !preg_match('~^[_0-9a-zA-Z-.s]+$~i',$_POST['message']))
        echo '<p align="'.$txt['align'].'">';


Edit 1:
Never mind. I figured it out. I forgot to add it to this line in upload.php:

Code: [Select]
$email_message = $_POST['email'] . " " . $_POST['fname'] . " " . $_POST['lname'] . " " . $_POST['uname'] . " " . $_POST['message'];
« Last Edit: November 23, 2010, 04:15:21 PM by Hawk »
Logged
Hawk

Saleh

  • Administrator
  • Full Member
  • *****
  • Offline Offline
  • Posts: 222
    • View Profile
    • PHP Simplicity
Re: Add a contact field to the form...
« Reply #27 on: November 24, 2010, 11:43:13 AM »

Very well :)
Logged

We don't need a reason to help people
 

+ Quick Reply

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.
Name: Email:
Verification:
Type the letters shown in the picture
Listen to the letters / Request another image
Type the letters shown in the picture:
What is the answer to one plus one? (in numbers):