Page 1 of 1
How to add file sending option to contact form ?
Posted: Mon Feb 07, 2005 4:58 pm
by Indrek
I tried to add file sending option in my contact form, but unsuccessfully.
http://www.balti.ee/proov/index.php?page=Kontakt
Can anyone teach me how to do it?
It would really help me alot.
Thanks.
Re: How to add file sending option to contact form ?
Posted: Mon Feb 07, 2005 5:35 pm
by 100rk
You have to add parameter 'enctype' to Your form
and then You have to use super-global variable $_FILES - take a look here:
http://php.net/manual/en/reserved.varia ... bles.files
I tried
Posted: Mon Feb 07, 2005 7:01 pm
by Indrek
I tried to do this, but it is still not working.
Maby i did something wrong?
Re: I tried
Posted: Mon Feb 07, 2005 9:59 pm
by 100rk
Indrek wrote:I tried to do this, but it is still not working.
Maby i did something wrong?
OK, here is what You want (I hope so):
- You have to create user defined plugin
- name it
- copy this code and paste it as code fo Your new plugin
Code: Select all
if (isset($_POST['ok_contactform'])) {
global $gCms;
echo '<div>';
echo 'Your Name:' . $_POST['name'] . '<br>';
echo 'Your Email:' . $_POST['email'] . '<br>';
echo 'Subject:' . $_POST['subject'] . '<br>';
echo 'Message:' . $_POST['message'] . '<br>';
if (($_FILES['file']['error']) > 0 ){
echo '<strong>And where is file?</strong>';
}
else {
$try = 0;
$dest_filename = '_contactform_' . $_FILES['file']['name'];
$dest_file = $gCms->config['uploads_path'] . '/' . $dest_filename;
while (file_exists($dest_file)) {
$dest_filename = $try . '_contactform_' . $_FILES['file']['name'];
$dest_file = $gCms->config["uploads_path"] . '/' . $dest_filename;
$try++;
}
$_FILES['file']['name'] = $dest_filename;
if ( ! move_uploaded_file( $_FILES['file']['tmp_name'], $dest_file)) {
echo '<strong>Error during copy file.</strong>';
}
else {
echo 'Saada Fail:' . $_FILES['file']['name'];
}
}
echo '</div>';
}
else {
echo '<div>';
echo '<form enctype="multipart/form-data" action="" method="post" name="contactForm" style="font-weight: bold;">';
echo '<input type="hidden" name="MAX_FILE_SIZE" value="100000">';
echo 'Your Name:';
echo '<input type="text" name="name" value="" size="50" style="width: 350px; border: solid 1px black; display: block; margin-bottom: 7px;">';
echo 'Your Email Address:';
echo '<input type="text" name="email" value="" size="50" style="width: 350px; border: solid 1px black; display: block; margin-bottom: 7px;">';
echo 'Subject:';
echo '<input type="text" name="subject" value="" size="50" style="width: 350px; border: solid 1px black; display: block; margin-bottom: 7px;">';
echo 'Saada Fail:';
echo '<input type="file" name="file" value="" size="50" style="width: 350px; border: solid 1px black; display: block; margin-bottom: 7px;">';
echo 'Message:';
echo '<TEXTAREA NAME="message" COLS="40" ROWS="10" style="width: 350px; border: solid 1px black; display: block; margin-bottom: 7px;"></textarea>';
echo '<input type="submit" name="ok_contactform" value="Submit">';
echo '<input type="reset" value="Clear">';
echo '</form>';
echo '</div>';
}
- and insert this plugin by inserting code
into Your pagecontent
File uloaded by this plugin (smaller than 100kB) will be in Your uploads directory. If no, write back.
contact form
Posted: Tue Feb 08, 2005 11:10 am
by Indrek
I used your code and it did work.
But, is it possible to send the file and text entered in fields to my email address from contact form.
I would like to make something like is in this page:
http://www.terraver.ee/index.php?page=32
Could you help?
It would mean a world to me.
Thanks.
Re: contact form
Posted: Tue Feb 08, 2005 12:23 pm
by 100rk
Indrek wrote:
But, is it possible to send the file and text entered in fields to my email address from contact form.
If You want to send plain text data by e-mail, just use simple PHP function 'mail()' - see
http://www.php.net/manual/en/function.mail.php . But if You want to send any attachment with e-mail message, it is not so easy - best way is to do this with some existed php class, like this one:
http://www.phpclasses.org/browse/package/1077.html
By the way, in case You have to include and use any class (defined in external file), module will be better then plugin.
I am sorry, You have to study a little bit, but don't worry - recommended class is very simple and quite well documented (example is also included).
Re: contact form
Posted: Wed Feb 16, 2005 12:05 pm
by 100rk
Indrek wrote:It would mean a world to me.
For saving Your life see
http://forum.cmsmadesimple.org/viewtopi ... ight=#2483