It's possible split the content of one var? For example in comments page the var $links (I think) come with this: delete | edit | reply but. Some client ask me for some different icons in this links so I need add some class to this elements for later play with them using CSS. So ... It's possible? Cheers and thanks in advance -- ReynierPM 5to Ing. Informática Maestro de poco, aprendiz de mucho
On Tuesday 28 November 2006 09:57, Reynier Perez Mira wrote:
It's possible split the content of one var? For example in comments page the var $links (I think) come with this: delete | edit | reply but. Some client ask me for some different icons in this links so I need add some class to this elements for later play with them using CSS. So ... It's possible? Cheers and thanks in advance
Maybe something here will help you: http://drupal.org/node/44708
I apologize if this isn't the right place to post this.. but I was hoping someone could help me out with a foreach loop.
I'm using the code from here http://drupal.org/node/68265 for a custom form in a page. I've modified it to display select menus - and they work just great except I can't get it to send anything other than a number. I've been all through the api stuff and have tried various methods for writing a foreach loop for the select menus, but everything seems to conflict with common.inc. Here's my modified code (hopefully this will display correctly):
<?php
$form['name'] = array( '#type' => 'textfield', '#title' => t('Username'), '#default_value' => $object['name'], '#size' => 30, '#maxlength' => 128, '#required' => TRUE, );
$form['eMail'] = array( '#type' => 'textfield', '#title' => t('E-mail Address'), '#default_value' => $object['eMail'], '#size' => 30, '#maxlength' => 128, '#required' => TRUE, );
//account option $account = array( '--'.t('Select').'--', t('Model'), t('Photographer'), t('Crew'), );
$form['assign'][$i] = array( '#type' => 'select', '#title' => t('Account purpose'), '#default_value' => $object['assign'][$i], '#options' => $account, '#required' => TRUE, '#description' => t('Choose which account your're applying for.'), );
$form['location'] = array( '#type' => 'textfield', '#title' => t('Location'), '#default_value' => $object['location'], '#size' => 30, '#maxlength' => 128, '#required' => TRUE, '#description' => t('Enter your city, state and country'), );
$form['age'] = array( '#type' => 'textfield', '#title' => t('Age'), '#default_value' => $object['age'], '#size' => 15, '#maxlength' => 128, '#required' => TRUE, '#description' => t('Enter your age'), );
//experience options $experience = array( '--'.t('Select').'--', t('Amateur/ Hobbyist'), t('Experienced Hobbyist'), t('Semi Professional'), t('Professional'), );
$form['exlevel'] = array( '#type' => 'select', '#title' => t('Experience Level'), '#default_value' => $object['exlevel'], '#options' => $experience, '#required' => TRUE, '#description' => t('Enter your experience level.'), );
//travel options $travel = array( '--'.t('Select').'--', t('Yes'), t('w/ expenses paid'), t('w/o expenses paid'), t('Only in my state'), t('Only in my city'), t('Depends on assignment'), t('No'), );
$form['willtravel'] = array( '#type' => 'select', '#title' => t('Will travel'), '#default_value' => $object['willtravel'], '#options' => $travel, '#required' => TRUE, '#description' => t('Are you willing to travel?'), );
$form['nudity'] = array( '#type' => 'textfield', '#title' => t('Nudity Level'), '#default_value' => $object['nudity'], '#size' => 30, '#maxlength' => 128, '#required' => TRUE, '#description' => t('Enter your level of experience or willingness for nude assignments.'), ); $form['compensation'] = array( '#type' => 'textfield', '#title' => t('Compensation'), '#default_value' => $object['compensation'], '#size' => 30, '#maxlength' => 128, '#required' => TRUE, '#description' => t('Example: DOA (Depends on Assignment), TFP, TFCD, Paid only, etc.'), ); $form['website'] = array( '#type' => 'textfield', '#title' => t('Web Site'), '#default_value' => $object['website'], '#size' => 30, '#maxlength' => 128, '#required' => FALSE, '#description' => t('If you have a personal web site, enter it here.'), ); $form['message'] = array( '#type' => 'textarea', '#title' => t('additional information'), '#default_value' => $object['message'], '#size' => 30, '#maxlength' => 128, '#rows' => 7, '#required' => FALSE, );
$form['file1'] = array( '#type' => 'file', '#title' => t('Four images are required for review.'), ); $form['file2'] = array( '#type' => 'file', ); $form['file3'] = array( '#type' => 'file', ); $form['file4'] = array( '#type' => 'file', );
$form['submit'] = array( '#type' => 'submit', '#value' => t('send email'), );
$form['#attributes']['enctype'] = 'multipart/form-data';
$output = drupal_get_form('contactform', $form); return $output;
// validation function for the contact form function contactform_validate($form_id, $form_values) { // first we validate if there is a email injection $finds = array("/bcc:/i", "/Content-Type:/i", "/Mime-Type:/i", "/MIME-Version:/i", "/multipart/mixed/i", "/boundary=/i", "/subject:/i", "/cc:/i", "/to:/i"); foreach($form_values as $value) foreach($finds as $find) if(preg_match($find,$value)) form_set_error('', '<h2 class="red center">Stop spamming</h2>');
// then we validate the email-adress if (!valid_email_address($form_values['eMail']) && !empty($form_values['eMail'])) form_set_error('', t('Please check the spelling of your email-adress.')); }
// submit function for the contact form function contactform_submit($form_id, $form_values) {
$from = $form_values['name'].' <'.$form_values['eMail'].'>'; $recipient = 'MX michelle@steelveils.com'; $subject = 'Application'; $account = $form_values['assign']; $location = $form_values['location']; $age = $form_values['age']; $experience = $form_values['exlevel']; $travel = $form_values['willtravel']; $nudity = $form_values['nudity']; $compensation = $form_values['compensation']; $website = $form_values['website']; $body = wordwrap($form_values['message']); $reply = 'Thank you for your application. Your application for an account is currently pending approval. Once it has been granted, you will receive further instructions in eMail.'; $goto = 'app-rec';
if (!flood_is_allowed('contact', variable_get('contact_hourly_threshold', 8))) { $output = t("You cannot send more than %number messages per hour. Please try again later.", array('%number' => variable_get('contact_hourly_threshold', 3))); drupal_set_message('<h3 class="red center">'.$output.'</h3>'); drupal_goto($goto); }else{ $attachment = FALSE; $trenner = md5(uniqid(time())); $headers .= "MIME-Version: 1.0\n"; $headers .= "From: $from\nReply-to: $from\nReturn-path: $from\nErrors-to: $from\nX-Mailer: Drupal\n"; $headers .= "Content-Type: multipart/mixed;\n\tboundary=$trenner\n"; $message .= "\n--$trenner\n"; $message .= "Content-Type: text/plain; charset=UTF-8;"."\n\n"; // sets the mime type $message .= "Account type: " .$account. "\n"; $message .= "Location: " .$location."\n"; $message .= "Age: " .$age."\n"; $message .= "Experience Level: " .$experience."\n"; $message .= "Will Travel: " .$travel."\n"; $message .= "Nudity Level: " .$nudity."\n"; $message .= "Compensation: " .$compensation."\n"; $message .= "Web Site: " .$website."\n"; $message .= $body. "\n"; $message .= "\n\n";
for($i=1;$i<=4;$i++){ $file = file_check_upload('file'.$i); if($file->filename){ $file->filepath = str_replace("\","\\",$file->filepath); $message .= "--$trenner"."\n"; $message .= "Content-Type:$file->filemime;\n\tname=$file->filename\n"; $message .= "Content-Transfer-Encoding: base64\n"; $message .= "Content-Disposition: attachment;\n\tfilename=$file->filename\n\n"; $filedata = fread(fopen($file->filepath, "rb"), $file->filesize); $message .= chunk_split(base64_encode($filedata)); $message .= "\n\n"; $attachment = TRUE; } } $message .= "--$trenner--";
// send Mail if($attachment) // use the php mail function if we have attachments mail($recipient, $subject, $message, $headers); else user_mail($recipient, $subject, $account, $location, $age, $experience, $travel, $nudity, $compensation, $website, $body, "From: $from\nReply-to: $from\nX-Mailer: Drupal\nReturn-path: $from\nErrors-to: $from");
// Reply user_mail($from, $subject, wordwrap($reply), "From: $recipient\nReply-to: $recipient\nX-Mailer: Drupal\nReturn-path: $recipient\nErrors-to: $recipient");
// Log the operation: flood_register_event('contact'); watchdog('mail', t('%name-from use contact form', array('%name-from' => theme('placeholder', $form_values['name'] ." <$from>"),)));
drupal_set_message('Your message has been sent to us'); drupal_goto($goto); } }
?>
Thanks! Michelle
First of all, the data structure for the select is not a simple array. It's an associative array. The key is the value that gets submitted by the form while the value for each key is the label to display. The actual renderer for the form does something like this:
foreach ($options as $key => $value) { print "<option value='$key'>$value</option>\m"; }
(That's NOT the actual Drupal code, but that's the sort of logic it does.)
So if you want to have a string value submitted, you'd need an option array like this:
$experience = array( t('Amateur/ Hobbyist') => t('Amateur/ Hobbyist'), t('Experienced Hobbyist') => t('Experienced Hobbyist'), t('Semi Professional') => t('Semi Professional'), t('Professional') => t('Professional'), );
Note that the "select one" option is not necessary; Drupal will add it for you if appropriate.
Secondly, it looks like you're doing things the very hard way. :-) Check out the webforms module, or similar; it can probably build you a form that will do what you need without you writing any actual code, and certainly not messing around with mail headers. Alternatively, you can have people submit a CCK-created node with image fields and use the actions module to send you a notice email to go view the node on the site. That way you even get a nice permanent record out of it.
When in doubt, make Drupal do it for you. :-)
Cheers.
On Friday 01 December 2006 18:59, MichelleX wrote:
I apologize if this isn't the right place to post this.. but I was hoping someone could help me out with a foreach loop.
I'm using the code from here http://drupal.org/node/68265 for a custom form in a page. I've modified it to display select menus - and they work just great except I can't get it to send anything other than a number. I've been all through the api stuff and have tried various methods for writing a foreach loop for the select menus, but everything seems to conflict with common.inc. Here's my modified code (hopefully this will display correctly):
<?php $form['name'] = array( '#type' => 'textfield', '#title' => t('Username'), '#default_value' => $object['name'], '#size' => 30, '#maxlength' => 128, '#required' => TRUE, ); $form['eMail'] = array( '#type' => 'textfield', '#title' => t('E-mail Address'), '#default_value' => $object['eMail'], '#size' => 30, '#maxlength' => 128, '#required' => TRUE, ); //account option $account = array( '--'.t('Select').'--', t('Model'), t('Photographer'), t('Crew'), ); $form['assign'][$i] = array( '#type' => 'select', '#title' => t('Account purpose'), '#default_value' => $object['assign'][$i], '#options' => $account, '#required' => TRUE, '#description' => t('Choose which account your\'re applying for.'), ); $form['location'] = array( '#type' => 'textfield', '#title' => t('Location'), '#default_value' => $object['location'], '#size' => 30, '#maxlength' => 128, '#required' => TRUE, '#description' => t('Enter your city, state and country'), ); $form['age'] = array( '#type' => 'textfield', '#title' => t('Age'), '#default_value' => $object['age'], '#size' => 15, '#maxlength' => 128, '#required' => TRUE, '#description' => t('Enter your age'), ); //experience options $experience = array( '--'.t('Select').'--', t('Amateur/ Hobbyist'), t('Experienced Hobbyist'), t('Semi Professional'), t('Professional'), ); $form['exlevel'] = array( '#type' => 'select', '#title' => t('Experience Level'), '#default_value' => $object['exlevel'], '#options' => $experience, '#required' => TRUE, '#description' => t('Enter your experience level.'), ); //travel options $travel = array( '--'.t('Select').'--', t('Yes'), t('w/ expenses paid'), t('w/o expenses paid'), t('Only in my state'), t('Only in my city'), t('Depends on assignment'), t('No'), ); $form['willtravel'] = array( '#type' => 'select', '#title' => t('Will travel'), '#default_value' => $object['willtravel'], '#options' => $travel, '#required' => TRUE, '#description' => t('Are you willing to travel?'), ); $form['nudity'] = array( '#type' => 'textfield', '#title' => t('Nudity Level'), '#default_value' => $object['nudity'], '#size' => 30, '#maxlength' => 128, '#required' => TRUE, '#description' => t('Enter your level of experience or willingness for nude assignments.'), ); $form['compensation'] = array( '#type' => 'textfield', '#title' => t('Compensation'), '#default_value' => $object['compensation'], '#size' => 30, '#maxlength' => 128, '#required' => TRUE, '#description' => t('Example: DOA (Depends on Assignment), TFP, TFCD, Paid only, etc.'), ); $form['website'] = array( '#type' => 'textfield', '#title' => t('Web Site'), '#default_value' => $object['website'], '#size' => 30, '#maxlength' => 128, '#required' => FALSE, '#description' => t('If you have a personal web site, enter it here.'), ); $form['message'] = array( '#type' => 'textarea', '#title' => t('additional information'), '#default_value' => $object['message'], '#size' => 30, '#maxlength' => 128, '#rows' => 7, '#required' => FALSE, ); $form['file1'] = array( '#type' => 'file', '#title' => t('Four images are required for review.'), ); $form['file2'] = array( '#type' => 'file', ); $form['file3'] = array( '#type' => 'file', ); $form['file4'] = array( '#type' => 'file', ); $form['submit'] = array( '#type' => 'submit', '#value' => t('send email'), ); $form['#attributes']['enctype'] = 'multipart/form-data'; $output = drupal_get_form('contactform', $form); return $output; // validation function for the contact form function contactform_validate($form_id, $form_values) { // first we validate if there is a email injection $finds = array("/bcc:/i", "/Content-Type:/i", "/Mime-Type:/i", "/MIME-Version:/i", "/multipart\/mixed/i", "/boundary=/i", "/subject:/i", "/cc:/i", "/to:/i"); foreach($form_values as $value) foreach($finds as $find) if(preg_match($find,$value)) form_set_error('', '<h2 class="red center">Stop spamming</h2>'); // then we validate the email-adress if (!valid_email_address($form_values['eMail']) && !empty($form_values['eMail'])) form_set_error('', t('Please check the spelling of your email-adress.')); } // submit function for the contact form function contactform_submit($form_id, $form_values) { $from = $form_values['name'].' <'.$form_values['eMail'].'>'; $recipient = 'MX <michelle@steelveils.com>'; $subject = 'Application'; $account = $form_values['assign']; $location = $form_values['location']; $age = $form_values['age']; $experience = $form_values['exlevel']; $travel = $form_values['willtravel']; $nudity = $form_values['nudity']; $compensation = $form_values['compensation']; $website = $form_values['website']; $body = wordwrap($form_values['message']); $reply = 'Thank you for your application. Your application for an account is currently pending approval. Once it has been granted, you will receive further instructions in eMail.'; $goto = 'app-rec'; if (!flood_is_allowed('contact', variable_get('contact_hourly_threshold', 8))) { $output = t("You cannot send more than %number messages per hour. Please try again later.", array('%number' => variable_get('contact_hourly_threshold', 3))); drupal_set_message('<h3 class="red center">'.$output.'</h3>'); drupal_goto($goto); }else{ $attachment = FALSE; $trenner = md5(uniqid(time())); $headers .= "MIME-Version: 1.0\n"; $headers .= "From: $from\nReply-to: $from\nReturn-path: $from\nErrors-to: $from\nX-Mailer: Drupal\n"; $headers .= "Content-Type: multipart/mixed;\n\tboundary=$trenner\n"; $message .= "\n--$trenner\n"; $message .= "Content-Type: text/plain; charset=UTF-8;"."\n\n"; // sets the mime type $message .= "Account type: " .$account. "\n"; $message .= "Location: " .$location."\n"; $message .= "Age: " .$age."\n"; $message .= "Experience Level: " .$experience."\n"; $message .= "Will Travel: " .$travel."\n"; $message .= "Nudity Level: " .$nudity."\n"; $message .= "Compensation: " .$compensation."\n"; $message .= "Web Site: " .$website."\n"; $message .= $body. "\n"; $message .= "\n\n"; for($i=1;$i<=4;$i++){ $file = file_check_upload('file'.$i); if($file->filename){ $file->filepath = str_replace("\\","\\\\",$file->filepath); $message .= "--$trenner"."\n"; $message .= "Content-Type:$file->filemime;\n\tname=$file->filename\n"; $message .= "Content-Transfer-Encoding: base64\n"; $message .= "Content-Disposition: attachment;\n\tfilename=$file->filename\n\n"; $filedata = fread(fopen($file->filepath, "rb"), $file->filesize); $message .= chunk_split(base64_encode($filedata)); $message .= "\n\n"; $attachment = TRUE; } } $message .= "--$trenner--"; // send Mail if($attachment) // use the php mail function if we have attachments mail($recipient, $subject, $message, $headers); else user_mail($recipient, $subject, $account, $location, $age, $experience, $travel, $nudity, $compensation, $website, $body, "From: $from\nReply-to: $from\nX-Mailer: Drupal\nReturn-path: $from\nErrors-to: $from"); // Reply user_mail($from, $subject, wordwrap($reply), "From: $recipient\nReply-to: $recipient\nX-Mailer: Drupal\nReturn-path: $recipient\nErrors-to: $recipient"); // Log the operation: flood_register_event('contact'); watchdog('mail', t('%name-from use contact form', array('%name-from' => theme('placeholder', $form_values['name'] ." <$from>"),))); drupal_set_message('Your message has been sent to us'); drupal_goto($goto); } } ?>
Thanks! Michelle
-- Steel Veils Photography. Digital Design. Custom Art. ________________________________________________________
www.SteelVeils.com | michelle@SteelVeils.com | 314.283.1081
Hi Larry - Thanks for the input. I think I got ya. I'll certainly look into Webform - anything other than this method is more than welcome, as long as it can do file attachments to the email.
Thanks again! Michelle
Larry Garfield wrote:
First of all, the data structure for the select is not a simple array. It's an associative array. The key is the value that gets submitted by the form while the value for each key is the label to display. The actual renderer for the form does something like this:
foreach ($options as $key => $value) { print "<option value='$key'>$value</option>\m"; }
(That's NOT the actual Drupal code, but that's the sort of logic it does.)
So if you want to have a string value submitted, you'd need an option array like this:
$experience = array( t('Amateur/ Hobbyist') => t('Amateur/ Hobbyist'), t('Experienced Hobbyist') => t('Experienced Hobbyist'), t('Semi Professional') => t('Semi Professional'), t('Professional') => t('Professional'), );
Note that the "select one" option is not necessary; Drupal will add it for you if appropriate.
Secondly, it looks like you're doing things the very hard way. :-) Check out the webforms module, or similar; it can probably build you a form that will do what you need without you writing any actual code, and certainly not messing around with mail headers. Alternatively, you can have people submit a CCK-created node with image fields and use the actions module to send you a notice email to go view the node on the site. That way you even get a nice permanent record out of it.
When in doubt, make Drupal do it for you. :-)
Cheers.
On Friday 01 December 2006 18:59, MichelleX wrote:
I apologize if this isn't the right place to post this.. but I was hoping someone could help me out with a foreach loop.
I'm using the code from here http://drupal.org/node/68265 for a custom form in a page. I've modified it to display select menus - and they work just great except I can't get it to send anything other than a number. I've been all through the api stuff and have tried various methods for writing a foreach loop for the select menus, but everything seems to conflict with common.inc. Here's my modified code (hopefully this will display correctly):
<?php $form['name'] = array( '#type' => 'textfield', '#title' => t('Username'), '#default_value' => $object['name'], '#size' => 30, '#maxlength' => 128, '#required' => TRUE, ); $form['eMail'] = array( '#type' => 'textfield', '#title' => t('E-mail Address'), '#default_value' => $object['eMail'], '#size' => 30, '#maxlength' => 128, '#required' => TRUE, ); //account option $account = array( '--'.t('Select').'--', t('Model'), t('Photographer'), t('Crew'), ); $form['assign'][$i] = array( '#type' => 'select', '#title' => t('Account purpose'), '#default_value' => $object['assign'][$i], '#options' => $account, '#required' => TRUE, '#description' => t('Choose which account your\'re applying for.'), ); $form['location'] = array( '#type' => 'textfield', '#title' => t('Location'), '#default_value' => $object['location'], '#size' => 30, '#maxlength' => 128, '#required' => TRUE, '#description' => t('Enter your city, state and country'), ); $form['age'] = array( '#type' => 'textfield', '#title' => t('Age'), '#default_value' => $object['age'], '#size' => 15, '#maxlength' => 128, '#required' => TRUE, '#description' => t('Enter your age'), ); //experience options $experience = array( '--'.t('Select').'--', t('Amateur/ Hobbyist'), t('Experienced Hobbyist'), t('Semi Professional'), t('Professional'), ); $form['exlevel'] = array( '#type' => 'select', '#title' => t('Experience Level'), '#default_value' => $object['exlevel'], '#options' => $experience, '#required' => TRUE, '#description' => t('Enter your experience level.'), ); //travel options $travel = array( '--'.t('Select').'--', t('Yes'), t('w/ expenses paid'), t('w/o expenses paid'), t('Only in my state'), t('Only in my city'), t('Depends on assignment'), t('No'), ); $form['willtravel'] = array( '#type' => 'select', '#title' => t('Will travel'), '#default_value' => $object['willtravel'], '#options' => $travel, '#required' => TRUE, '#description' => t('Are you willing to travel?'), ); $form['nudity'] = array( '#type' => 'textfield', '#title' => t('Nudity Level'), '#default_value' => $object['nudity'], '#size' => 30, '#maxlength' => 128, '#required' => TRUE, '#description' => t('Enter your level of experience or willingness for nude assignments.'), ); $form['compensation'] = array( '#type' => 'textfield', '#title' => t('Compensation'), '#default_value' => $object['compensation'], '#size' => 30, '#maxlength' => 128, '#required' => TRUE, '#description' => t('Example: DOA (Depends on Assignment), TFP, TFCD, Paid only, etc.'), ); $form['website'] = array( '#type' => 'textfield', '#title' => t('Web Site'), '#default_value' => $object['website'], '#size' => 30, '#maxlength' => 128, '#required' => FALSE, '#description' => t('If you have a personal web site, enter it here.'), ); $form['message'] = array( '#type' => 'textarea', '#title' => t('additional information'), '#default_value' => $object['message'], '#size' => 30, '#maxlength' => 128, '#rows' => 7, '#required' => FALSE, ); $form['file1'] = array( '#type' => 'file', '#title' => t('Four images are required for review.'), ); $form['file2'] = array( '#type' => 'file', ); $form['file3'] = array( '#type' => 'file', ); $form['file4'] = array( '#type' => 'file', ); $form['submit'] = array( '#type' => 'submit', '#value' => t('send email'), ); $form['#attributes']['enctype'] = 'multipart/form-data'; $output = drupal_get_form('contactform', $form); return $output; // validation function for the contact form function contactform_validate($form_id, $form_values) { // first we validate if there is a email injection $finds = array("/bcc:/i", "/Content-Type:/i", "/Mime-Type:/i", "/MIME-Version:/i", "/multipart\/mixed/i", "/boundary=/i", "/subject:/i", "/cc:/i", "/to:/i"); foreach($form_values as $value) foreach($finds as $find) if(preg_match($find,$value)) form_set_error('', '<h2 class="red center">Stop spamming</h2>'); // then we validate the email-adress if (!valid_email_address($form_values['eMail']) && !empty($form_values['eMail'])) form_set_error('', t('Please check the spelling of your email-adress.')); } // submit function for the contact form function contactform_submit($form_id, $form_values) { $from = $form_values['name'].' <'.$form_values['eMail'].'>'; $recipient = 'MX <michelle@steelveils.com>'; $subject = 'Application'; $account = $form_values['assign']; $location = $form_values['location']; $age = $form_values['age']; $experience = $form_values['exlevel']; $travel = $form_values['willtravel']; $nudity = $form_values['nudity']; $compensation = $form_values['compensation']; $website = $form_values['website']; $body = wordwrap($form_values['message']); $reply = 'Thank you for your application. Your application for an account is currently pending approval. Once it has been granted, you will receive further instructions in eMail.'; $goto = 'app-rec'; if (!flood_is_allowed('contact', variable_get('contact_hourly_threshold', 8))) { $output = t("You cannot send more than %number messages per hour. Please try again later.", array('%number' => variable_get('contact_hourly_threshold', 3))); drupal_set_message('<h3 class="red center">'.$output.'</h3>'); drupal_goto($goto); }else{ $attachment = FALSE; $trenner = md5(uniqid(time())); $headers .= "MIME-Version: 1.0\n"; $headers .= "From: $from\nReply-to: $from\nReturn-path: $from\nErrors-to: $from\nX-Mailer: Drupal\n"; $headers .= "Content-Type: multipart/mixed;\n\tboundary=$trenner\n"; $message .= "\n--$trenner\n"; $message .= "Content-Type: text/plain; charset=UTF-8;"."\n\n"; // sets the mime type $message .= "Account type: " .$account. "\n"; $message .= "Location: " .$location."\n"; $message .= "Age: " .$age."\n"; $message .= "Experience Level: " .$experience."\n"; $message .= "Will Travel: " .$travel."\n"; $message .= "Nudity Level: " .$nudity."\n"; $message .= "Compensation: " .$compensation."\n"; $message .= "Web Site: " .$website."\n"; $message .= $body. "\n"; $message .= "\n\n"; for($i=1;$i<=4;$i++){ $file = file_check_upload('file'.$i); if($file->filename){ $file->filepath = str_replace("\\","\\\\",$file->filepath); $message .= "--$trenner"."\n"; $message .= "Content-Type:$file->filemime;\n\tname=$file->filename\n"; $message .= "Content-Transfer-Encoding: base64\n"; $message .= "Content-Disposition: attachment;\n\tfilename=$file->filename\n\n"; $filedata = fread(fopen($file->filepath, "rb"), $file->filesize); $message .= chunk_split(base64_encode($filedata)); $message .= "\n\n"; $attachment = TRUE; } } $message .= "--$trenner--"; // send Mail if($attachment) // use the php mail function if we have attachments mail($recipient, $subject, $message, $headers); else user_mail($recipient, $subject, $account, $location, $age, $experience, $travel, $nudity, $compensation, $website, $body, "From: $from\nReply-to: $from\nX-Mailer: Drupal\nReturn-path: $from\nErrors-to: $from"); // Reply user_mail($from, $subject, wordwrap($reply), "From: $recipient\nReply-to: $recipient\nX-Mailer: Drupal\nReturn-path: $recipient\nErrors-to: $recipient"); // Log the operation: flood_register_event('contact'); watchdog('mail', t('%name-from use contact form', array('%name-from' => theme('placeholder', $form_values['name'] ." <$from>"),))); drupal_set_message('Your message has been sent to us'); drupal_goto($goto); } } ?>
Thanks! Michelle
-- Steel Veils Photography. Digital Design. Custom Art. ________________________________________________________
www.SteelVeils.com | michelle@SteelVeils.com | 314.283.1081
Also have a look at the Send module, I think it's called. It's a more robust emailing system that a lot of other stuff is built off of. I've not used it, but it could be useful.
On Saturday 02 December 2006 07:40, MichelleX wrote:
Hi Larry - Thanks for the input. I think I got ya. I'll certainly look into Webform - anything other than this method is more than welcome, as long as it can do file attachments to the email.
Thanks again! Michelle
Larry Garfield wrote:
First of all, the data structure for the select is not a simple array. It's an associative array. The key is the value that gets submitted by the form while the value for each key is the label to display. The actual renderer for the form does something like this:
foreach ($options as $key => $value) { print "<option value='$key'>$value</option>\m"; }
(That's NOT the actual Drupal code, but that's the sort of logic it does.)
So if you want to have a string value submitted, you'd need an option array like this:
$experience = array( t('Amateur/ Hobbyist') => t('Amateur/ Hobbyist'), t('Experienced Hobbyist') => t('Experienced Hobbyist'), t('Semi Professional') => t('Semi Professional'), t('Professional') => t('Professional'), );
Note that the "select one" option is not necessary; Drupal will add it for you if appropriate.
Secondly, it looks like you're doing things the very hard way. :-) Check out the webforms module, or similar; it can probably build you a form that will do what you need without you writing any actual code, and certainly not messing around with mail headers. Alternatively, you can have people submit a CCK-created node with image fields and use the actions module to send you a notice email to go view the node on the site. That way you even get a nice permanent record out of it.
When in doubt, make Drupal do it for you. :-)
Cheers.
On Friday 01 December 2006 18:59, MichelleX wrote:
I apologize if this isn't the right place to post this.. but I was hoping someone could help me out with a foreach loop.
I'm using the code from here http://drupal.org/node/68265 for a custom form in a page. I've modified it to display select menus - and they work just great except I can't get it to send anything other than a number. I've been all through the api stuff and have tried various methods for writing a foreach loop for the select menus, but everything seems to conflict with common.inc. Here's my modified code (hopefully this will display correctly):
<?php $form['name'] = array( '#type' => 'textfield', '#title' => t('Username'), '#default_value' => $object['name'], '#size' => 30, '#maxlength' => 128, '#required' => TRUE, ); $form['eMail'] = array( '#type' => 'textfield', '#title' => t('E-mail Address'), '#default_value' => $object['eMail'], '#size' => 30, '#maxlength' => 128, '#required' => TRUE, ); //account option $account = array( '--'.t('Select').'--', t('Model'), t('Photographer'), t('Crew'), ); $form['assign'][$i] = array( '#type' => 'select', '#title' => t('Account purpose'), '#default_value' => $object['assign'][$i], '#options' => $account, '#required' => TRUE, '#description' => t('Choose which account your\'re applying for.'), ); $form['location'] = array( '#type' => 'textfield', '#title' => t('Location'), '#default_value' => $object['location'], '#size' => 30, '#maxlength' => 128, '#required' => TRUE, '#description' => t('Enter your city, state and country'), ); $form['age'] = array( '#type' => 'textfield', '#title' => t('Age'), '#default_value' => $object['age'], '#size' => 15, '#maxlength' => 128, '#required' => TRUE, '#description' => t('Enter your age'), ); //experience options $experience = array( '--'.t('Select').'--', t('Amateur/ Hobbyist'), t('Experienced Hobbyist'), t('Semi Professional'), t('Professional'), ); $form['exlevel'] = array( '#type' => 'select', '#title' => t('Experience Level'), '#default_value' => $object['exlevel'], '#options' => $experience, '#required' => TRUE, '#description' => t('Enter your experience level.'), ); //travel options $travel = array( '--'.t('Select').'--', t('Yes'), t('w/ expenses paid'), t('w/o expenses paid'), t('Only in my state'), t('Only in my city'), t('Depends on assignment'), t('No'), ); $form['willtravel'] = array( '#type' => 'select', '#title' => t('Will travel'), '#default_value' => $object['willtravel'], '#options' => $travel, '#required' => TRUE, '#description' => t('Are you willing to travel?'), ); $form['nudity'] = array( '#type' => 'textfield', '#title' => t('Nudity Level'), '#default_value' => $object['nudity'], '#size' => 30, '#maxlength' => 128, '#required' => TRUE, '#description' => t('Enter your level of experience or willingness for nude assignments.'), ); $form['compensation'] = array( '#type' => 'textfield', '#title' => t('Compensation'), '#default_value' => $object['compensation'], '#size' => 30, '#maxlength' => 128, '#required' => TRUE, '#description' => t('Example: DOA (Depends on Assignment), TFP, TFCD, Paid only, etc.'), ); $form['website'] = array( '#type' => 'textfield', '#title' => t('Web Site'), '#default_value' => $object['website'], '#size' => 30, '#maxlength' => 128, '#required' => FALSE, '#description' => t('If you have a personal web site, enter it here.'), ); $form['message'] = array( '#type' => 'textarea', '#title' => t('additional information'), '#default_value' => $object['message'], '#size' => 30, '#maxlength' => 128, '#rows' => 7, '#required' => FALSE, ); $form['file1'] = array( '#type' => 'file', '#title' => t('Four images are required for review.'), ); $form['file2'] = array( '#type' => 'file', ); $form['file3'] = array( '#type' => 'file', ); $form['file4'] = array( '#type' => 'file', ); $form['submit'] = array( '#type' => 'submit', '#value' => t('send email'), ); $form['#attributes']['enctype'] = 'multipart/form-data'; $output = drupal_get_form('contactform', $form); return $output; // validation function for the contact form function contactform_validate($form_id, $form_values) { // first we validate if there is a email injection $finds = array("/bcc:/i", "/Content-Type:/i", "/Mime-Type:/i", "/MIME-Version:/i", "/multipart\/mixed/i", "/boundary=/i", "/subject:/i", "/cc:/i", "/to:/i"); foreach($form_values as $value) foreach($finds as $find) if(preg_match($find,$value)) form_set_error('', '<h2 class="red center">Stop spamming</h2>'); // then we validate the email-adress if (!valid_email_address($form_values['eMail']) && !empty($form_values['eMail'])) form_set_error('', t('Please check the spelling of your email-adress.')); } // submit function for the contact form function contactform_submit($form_id, $form_values) { $from = $form_values['name'].' <'.$form_values['eMail'].'>'; $recipient = 'MX <michelle@steelveils.com>'; $subject = 'Application'; $account = $form_values['assign']; $location = $form_values['location']; $age = $form_values['age']; $experience = $form_values['exlevel']; $travel = $form_values['willtravel']; $nudity = $form_values['nudity']; $compensation = $form_values['compensation']; $website = $form_values['website']; $body = wordwrap($form_values['message']); $reply = 'Thank you for your application. Your application for an account is currently pending approval. Once it has been granted, you will receive further instructions in eMail.'; $goto = 'app-rec'; if (!flood_is_allowed('contact', variable_get('contact_hourly_threshold', 8))) { $output = t("You cannot send more than %number messages per hour. Please try again later.", array('%number' => variable_get('contact_hourly_threshold', 3))); drupal_set_message('<h3 class="red center">'.$output.'</h3>'); drupal_goto($goto); }else{ $attachment = FALSE; $trenner = md5(uniqid(time())); $headers .= "MIME-Version: 1.0\n"; $headers .= "From: $from\nReply-to: $from\nReturn-path: $from\nErrors-to: $from\nX-Mailer: Drupal\n"; $headers .= "Content-Type: multipart/mixed;\n\tboundary=$trenner\n"; $message .= "\n--$trenner\n"; $message .= "Content-Type: text/plain; charset=UTF-8;"."\n\n"; // sets the mime type $message .= "Account type: " .$account. "\n"; $message .= "Location: " .$location."\n"; $message .= "Age: " .$age."\n"; $message .= "Experience Level: " .$experience."\n"; $message .= "Will Travel: " .$travel."\n"; $message .= "Nudity Level: " .$nudity."\n"; $message .= "Compensation: " .$compensation."\n"; $message .= "Web Site: " .$website."\n"; $message .= $body. "\n"; $message .= "\n\n"; for($i=1;$i<=4;$i++){ $file = file_check_upload('file'.$i); if($file->filename){ $file->filepath = str_replace("\\","\\\\",$file->filepath); $message .= "--$trenner"."\n"; $message .= "Content-Type:$file->filemime;\n\tname=$file->filename\n"; $message .= "Content-Transfer-Encoding: base64\n"; $message .= "Content-Disposition: attachment;\n\tfilename=$file->filename\n\n"; $filedata = fread(fopen($file->filepath, "rb"), $file->filesize); $message .= chunk_split(base64_encode($filedata)); $message .= "\n\n"; $attachment = TRUE; } } $message .= "--$trenner--"; // send Mail if($attachment) // use the php mail function if we have attachments mail($recipient, $subject, $message, $headers); else user_mail($recipient, $subject, $account, $location, $age, $experience, $travel, $nudity, $compensation, $website, $body, "From: $from\nReply-to: $from\nX-Mailer: Drupal\nReturn-path: $from\nErrors-to: $from"); // Reply user_mail($from, $subject, wordwrap($reply), "From: $recipient\nReply-to: $recipient\nX-Mailer: Drupal\nReturn-path: $recipient\nErrors-to: $recipient"); // Log the operation: flood_register_event('contact'); watchdog('mail', t('%name-from use contact form', array('%name-from' => theme('placeholder', $form_values['name'] ." <$from>"),))); drupal_set_message('Your message has been sent to us'); drupal_goto($goto); } } ?>
Thanks! Michelle
-- Steel Veils Photography. Digital Design. Custom Art. ________________________________________________________
www.SteelVeils.com | michelle@SteelVeils.com | 314.283.1081
-- Steel Veils Photography. Digital Design. Custom Art. ________________________________________________________
www.SteelVeils.com | michelle@SteelVeils.com | 314.283.1081
Well thank you. I've made note of that one too. But actually.. and I feel like an idiot now... after playing around with CCK a bit more, I've decided to scrap the whole email idea. This method will make registration authorization a lot easier. I sincerely appreciate your input, thank you.
Michelle
Larry Garfield wrote:
Also have a look at the Send module, I think it's called. It's a more robust emailing system that a lot of other stuff is built off of. I've not used it, but it could be useful.
On Saturday 02 December 2006 07:40, MichelleX wrote:
Hi Larry - Thanks for the input. I think I got ya. I'll certainly look into Webform - anything other than this method is more than welcome, as long as it can do file attachments to the email.
Thanks again! Michelle
Larry Garfield wrote:
First of all, the data structure for the select is not a simple array. It's an associative array. The key is the value that gets submitted by the form while the value for each key is the label to display. The actual renderer for the form does something like this:
foreach ($options as $key => $value) { print "<option value='$key'>$value</option>\m"; }
(That's NOT the actual Drupal code, but that's the sort of logic it does.)
So if you want to have a string value submitted, you'd need an option array like this:
$experience = array( t('Amateur/ Hobbyist') => t('Amateur/ Hobbyist'), t('Experienced Hobbyist') => t('Experienced Hobbyist'), t('Semi Professional') => t('Semi Professional'), t('Professional') => t('Professional'), );
Note that the "select one" option is not necessary; Drupal will add it for you if appropriate.
Secondly, it looks like you're doing things the very hard way. :-) Check out the webforms module, or similar; it can probably build you a form that will do what you need without you writing any actual code, and certainly not messing around with mail headers. Alternatively, you can have people submit a CCK-created node with image fields and use the actions module to send you a notice email to go view the node on the site. That way you even get a nice permanent record out of it.
When in doubt, make Drupal do it for you. :-)
Cheers.
On Friday 01 December 2006 18:59, MichelleX wrote:
I apologize if this isn't the right place to post this.. but I was hoping someone could help me out with a foreach loop.
I'm using the code from here http://drupal.org/node/68265 for a custom form in a page. I've modified it to display select menus - and they work just great except I can't get it to send anything other than a number. I've been all through the api stuff and have tried various methods for writing a foreach loop for the select menus, but everything seems to conflict with common.inc. Here's my modified code (hopefully this will display correctly):
<?php $form['name'] = array( '#type' => 'textfield', '#title' => t('Username'), '#default_value' => $object['name'], '#size' => 30, '#maxlength' => 128, '#required' => TRUE, ); $form['eMail'] = array( '#type' => 'textfield', '#title' => t('E-mail Address'), '#default_value' => $object['eMail'], '#size' => 30, '#maxlength' => 128, '#required' => TRUE, ); //account option $account = array( '--'.t('Select').'--', t('Model'), t('Photographer'), t('Crew'), ); $form['assign'][$i] = array( '#type' => 'select', '#title' => t('Account purpose'), '#default_value' => $object['assign'][$i], '#options' => $account, '#required' => TRUE, '#description' => t('Choose which account your\'re applying for.'), ); $form['location'] = array( '#type' => 'textfield', '#title' => t('Location'), '#default_value' => $object['location'], '#size' => 30, '#maxlength' => 128, '#required' => TRUE, '#description' => t('Enter your city, state and country'), ); $form['age'] = array( '#type' => 'textfield', '#title' => t('Age'), '#default_value' => $object['age'], '#size' => 15, '#maxlength' => 128, '#required' => TRUE, '#description' => t('Enter your age'), ); //experience options $experience = array( '--'.t('Select').'--', t('Amateur/ Hobbyist'), t('Experienced Hobbyist'), t('Semi Professional'), t('Professional'), ); $form['exlevel'] = array( '#type' => 'select', '#title' => t('Experience Level'), '#default_value' => $object['exlevel'], '#options' => $experience, '#required' => TRUE, '#description' => t('Enter your experience level.'), ); //travel options $travel = array( '--'.t('Select').'--', t('Yes'), t('w/ expenses paid'), t('w/o expenses paid'), t('Only in my state'), t('Only in my city'), t('Depends on assignment'), t('No'), ); $form['willtravel'] = array( '#type' => 'select', '#title' => t('Will travel'), '#default_value' => $object['willtravel'], '#options' => $travel, '#required' => TRUE, '#description' => t('Are you willing to travel?'), ); $form['nudity'] = array( '#type' => 'textfield', '#title' => t('Nudity Level'), '#default_value' => $object['nudity'], '#size' => 30, '#maxlength' => 128, '#required' => TRUE, '#description' => t('Enter your level of experience or willingness for nude assignments.'), ); $form['compensation'] = array( '#type' => 'textfield', '#title' => t('Compensation'), '#default_value' => $object['compensation'], '#size' => 30, '#maxlength' => 128, '#required' => TRUE, '#description' => t('Example: DOA (Depends on Assignment), TFP, TFCD, Paid only, etc.'), ); $form['website'] = array( '#type' => 'textfield', '#title' => t('Web Site'), '#default_value' => $object['website'], '#size' => 30, '#maxlength' => 128, '#required' => FALSE, '#description' => t('If you have a personal web site, enter it here.'), ); $form['message'] = array( '#type' => 'textarea', '#title' => t('additional information'), '#default_value' => $object['message'], '#size' => 30, '#maxlength' => 128, '#rows' => 7, '#required' => FALSE, ); $form['file1'] = array( '#type' => 'file', '#title' => t('Four images are required for review.'), ); $form['file2'] = array( '#type' => 'file', ); $form['file3'] = array( '#type' => 'file', ); $form['file4'] = array( '#type' => 'file', ); $form['submit'] = array( '#type' => 'submit', '#value' => t('send email'), ); $form['#attributes']['enctype'] = 'multipart/form-data'; $output = drupal_get_form('contactform', $form); return $output; // validation function for the contact form function contactform_validate($form_id, $form_values) { // first we validate if there is a email injection $finds = array("/bcc:/i", "/Content-Type:/i", "/Mime-Type:/i", "/MIME-Version:/i", "/multipart\/mixed/i", "/boundary=/i", "/subject:/i", "/cc:/i", "/to:/i"); foreach($form_values as $value) foreach($finds as $find) if(preg_match($find,$value)) form_set_error('', '<h2 class="red center">Stop spamming</h2>'); // then we validate the email-adress if (!valid_email_address($form_values['eMail']) && !empty($form_values['eMail'])) form_set_error('', t('Please check the spelling of your email-adress.')); } // submit function for the contact form function contactform_submit($form_id, $form_values) { $from = $form_values['name'].' <'.$form_values['eMail'].'>'; $recipient = 'MX <michelle@steelveils.com>'; $subject = 'Application'; $account = $form_values['assign']; $location = $form_values['location']; $age = $form_values['age']; $experience = $form_values['exlevel']; $travel = $form_values['willtravel']; $nudity = $form_values['nudity']; $compensation = $form_values['compensation']; $website = $form_values['website']; $body = wordwrap($form_values['message']); $reply = 'Thank you for your application. Your application for an account is currently pending approval. Once it has been granted, you will receive further instructions in eMail.'; $goto = 'app-rec'; if (!flood_is_allowed('contact', variable_get('contact_hourly_threshold', 8))) { $output = t("You cannot send more than %number messages per hour. Please try again later.", array('%number' => variable_get('contact_hourly_threshold', 3))); drupal_set_message('<h3 class="red center">'.$output.'</h3>'); drupal_goto($goto); }else{ $attachment = FALSE; $trenner = md5(uniqid(time())); $headers .= "MIME-Version: 1.0\n"; $headers .= "From: $from\nReply-to: $from\nReturn-path: $from\nErrors-to: $from\nX-Mailer: Drupal\n"; $headers .= "Content-Type: multipart/mixed;\n\tboundary=$trenner\n"; $message .= "\n--$trenner\n"; $message .= "Content-Type: text/plain; charset=UTF-8;"."\n\n"; // sets the mime type $message .= "Account type: " .$account. "\n"; $message .= "Location: " .$location."\n"; $message .= "Age: " .$age."\n"; $message .= "Experience Level: " .$experience."\n"; $message .= "Will Travel: " .$travel."\n"; $message .= "Nudity Level: " .$nudity."\n"; $message .= "Compensation: " .$compensation."\n"; $message .= "Web Site: " .$website."\n"; $message .= $body. "\n"; $message .= "\n\n"; for($i=1;$i<=4;$i++){ $file = file_check_upload('file'.$i); if($file->filename){ $file->filepath = str_replace("\\","\\\\",$file->filepath); $message .= "--$trenner"."\n"; $message .= "Content-Type:$file->filemime;\n\tname=$file->filename\n"; $message .= "Content-Transfer-Encoding: base64\n"; $message .= "Content-Disposition: attachment;\n\tfilename=$file->filename\n\n"; $filedata = fread(fopen($file->filepath, "rb"), $file->filesize); $message .= chunk_split(base64_encode($filedata)); $message .= "\n\n"; $attachment = TRUE; } } $message .= "--$trenner--"; // send Mail if($attachment) // use the php mail function if we have attachments mail($recipient, $subject, $message, $headers); else user_mail($recipient, $subject, $account, $location, $age, $experience, $travel, $nudity, $compensation, $website, $body, "From: $from\nReply-to: $from\nX-Mailer: Drupal\nReturn-path: $from\nErrors-to: $from"); // Reply user_mail($from, $subject, wordwrap($reply), "From: $recipient\nReply-to: $recipient\nX-Mailer: Drupal\nReturn-path: $recipient\nErrors-to: $recipient"); // Log the operation: flood_register_event('contact'); watchdog('mail', t('%name-from use contact form', array('%name-from' => theme('placeholder', $form_values['name'] ." <$from>"),))); drupal_set_message('Your message has been sent to us'); drupal_goto($goto); } } ?>
Thanks! Michelle
-- Steel Veils Photography. Digital Design. Custom Art. ________________________________________________________
www.SteelVeils.com | michelle@SteelVeils.com | 314.283.1081
-- Steel Veils Photography. Digital Design. Custom Art. ________________________________________________________
www.SteelVeils.com | michelle@SteelVeils.com | 314.283.1081
Hey guys -
I know Realtor type web sites have been created using Drupal, but my client has inquired about some things I'm having difficulty finding answers to on the Drupal site. So, I'm hoping someone here may know the answers.
- Is it possible to have a custom IDX option? - Is it possible for users to save searches and have them emailed to them?
Any ideas are greatly appreciated.
Thanks, Michelle
"MichelleX" wrote:
Hey guys -
I know Realtor type web sites have been created using Drupal, but my client has inquired about some things I'm having difficulty finding answers to on the Drupal site. So, I'm hoping someone here may know the answers.
- Is it possible to have a custom IDX option? - Is it possible for users to
save searches and have them emailed to them?
Any ideas are greatly appreciated.
Thanks, Michelle
I totally dig Drupal, so just know that.
However, for two clients in the real estate business, we elected to use Open-Realty and Joomla. The reason is that Open-Realty has a "CMS wrapper mode", where you can tell O-R that you will be "inserting" its content and such into some other CMS.
This does not work with Drupal, because of its 'single index' structure and because of a few other DB technicalities. Rather, it might be more accurate to say: To make O-R work with Drupal was not cost beneficial over other tools to integrate a CMS with Open-Realty.
I would _love_ to continue with our stalled project of creating an integrated O-R/Drupal distribution, or even some form of (complex?) module to handle the mediation between the two.
Another very useful and stable CMS that works just brilliantly with Open-Realty (and Drupal, too!) is pMachine Free. This is still available, is not open source, per se, and is not actively developed (except for a life-time commitment to security issues). The old pMachine became Expression Engine and is very pricey and closed-source. Then pMachine became pMachine Free and is quite cool and easy an we use it with a handful of clients who just love it and won't change (it's very light on its feet, too, so you don't have the slow-down that you get with Drupal.)
Anyway, I've been through the "real estate integration" thing for many hard months, and I think that we've arrived at a solution that maintains an open-source integrity (Open-Realty is not GPL'ed, but it is open-source under its own license, which is minimally requiring of an HTML comment remaining intact.)
I know this isn't exactly in reply to your two questions (which others can handle more accurately). It's just that real estate web sites are so specialized that one needs a dedicated RE tool (I think) to handle the structure of Agents, Offices, Property Classes (types) and so on. It may be better to use some kind of stand-alone tool along with a CMS to get just the mix you want.