Please login or register.

Login with username, password and session length
Advanced search  

News:

Latest sNews - sNews 1.7 - with its own forums - for discussion and user mods.

Author Topic: Add Required Fields in Contact Form - how?  (Read 2115 times)

mishg

  • Newbie
  • *
  • Karma: 0
  • Posts: 8
    • http://in development...
Add Required Fields in Contact Form - how?
« on: January 08, 2007, 11:30:45 pm »

Hello,

I'm using sNews version 1.4 with the comments validation mod by bramsyuur and need some help with the contact form.  I have a two part question.  First, my client would like to add more required fields to the form.  What part of the snews.php file can I find the 'required field' function?  I know the field called 'name' is set as default.  

This is what the mailing part of that form says for the form:
Code: [Select]
if (isset($_POST['contactform'])) {$headers = "From: " . strtolower($_POST['email']) . "\r\n" .
       'X-Mailer: PHP/' . phpversion() . "\r\n" .
       "Return-Path: " . s('email') . "\r\n";
$to = s('website_email');
$subject = s('contact_subject');
$body = l('name') .": ". $_POST['name'] ."\n";
$body .= l('email') .": ". $_POST['email'] ."\n";
$body .= l('url') .": ". $_POST['weblink'] ."\n\n";
$body .= l('job_title') .": ". $_POST['job_title'] ."\n\n";
$body .= l('employer') .": ". $_POST['employer'] ."\n\n";
$body .= l('address') .": ". $_POST['address'] ."\n\n";
$body .= l('city') .": ". $_POST['city'] ."\n\n";
$body .= l('state') .": ". $_POST['state'] ."\n\n";
$body .= l('zip') .": ". $_POST['zip'] ."\n\n";
$body .= l('help_campaign') .": ". $_POST['help_campaign'] ."\n\n";
$body .= l('contribute') .": ". $_POST['contribute'] ."\n\n";
$body .= l('activate_com') .": ". $_POST['activate_com'] ."\n\n";
$body .= l('message') .": ". $_POST['message'] ."\n";
if (strlen(clean($_POST['name'])) > 1 AND strlen(clean($_POST['message'])) > 1 AND audit()) {
    mail($to, $subject, $body, $headers);
echo "

". l('contact_sent') ."

";
  echo "

". l('backhome') ."

";
} else {
echo "

". l('contact_not_sent') ."

";
echo "

". l('message_error') ."

";
echo "

". l('backhome') ."

";

}}}
Is this close to what I might need to use for other required fields (changing field name of course)?
Code: [Select]
if (strlen(clean($_POST['name'])) > 1 AND strlen(clean($_POST['message'])) > 1 AND audit())My second question: Is it possible to define multiple contact forms withing sNews?  If so, what needs to be defined to allow the second form to display?



Thanks for your help.
Logged

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6020
  • Semantically Challenged
    • snews.ca
Add Required Fields in Contact Form - how?
« Reply #1 on: January 08, 2007, 11:55:02 pm »

The short answer... there's more to adding new fields to the form than just trying to re-use something that is already there. Each field you create must have a place in a table in the database made for the information it collects and sends to the database... for storage. Then, there also need to be fields that  retrieve it from the database table and display it for editing or viewing purposes. And there would be more stuff to include as well, depending on what the information is used for within sNews. Best advice - get a good book on PHp & MySQL and start learning. What needs to be done can't be covered in here. :)
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

mishg

  • Newbie
  • *
  • Karma: 0
  • Posts: 8
    • http://in development...
Add Required Fields in Contact Form - how?
« Reply #2 on: January 09, 2007, 12:01:48 am »

Thanks.  I did find that adding the field I needed to make 'required' to this line works
Code: [Select]
if (strlen(clean($_POST['name'])) > 1 AND strlen(clean($_POST['message'])) > 1 AND strlen(clean($_POST['address'])) > 1 AND audit())Obviously, you need to have this set as a real form field in the html portion of the form for it to matter.  At least this question is solved.

I understand why adding additional forms isn't covered.  I was hoping someone else had tried and succeeded and kind enough to share the process.

I appreciate the timely response.  You're most kind.  

Good day!
Logged