2 personman May 23, 2006 15:19

Thanks for the reply Personman.
I just had a look and you were spot on. 1.6-alpha does have this feature. However having read through the docs, it seems an upgrade will screw up my custom skin. I imagine 1.8-alpha will probably be the same.
Looks like i'm either going to have to spend time upgrading and modifying my skin or creating a contact form myself. Either way, its at least an hours work 8|
Its ironic that I chose to use B2EVO for this website so I could have a break from coding! :D
Thanks again for the help Personman. If anything else springs to mind, please let me know.
Upgrading a skin from 0.9.x to 1.6 isn't really that hard. Here's a guide:
http://wonderwinds.com/hackblog.php/2005/11/27/converting_old_skins_to_the_new_way
If you skip the optional steps, you can probably have it done in about 15 minutes.
If you look in skin/<skin name>/_main.php you'll see that it uses a switch for $disp, so you could code a custom page to handle your email and trigger it with disp=email in the query string. That way you do minimal coding and it automatically fits in your blog skin ;)
¥
Thanks a lot guys.
I decided against upgrading for the time being. Can't afford any downtime right now. I'll try that another day 8|
I used the $disp switch as Yabba described. 10 minutes to research the _main file and another 10 to do a (rudimentary) email script. I'll outline what I did below for anyone else that needs to do this.
Firstly, open up /skins/<skin name>/_main.php and find the line that begins 'switch( $disp )'.
Underneath the bottom 'case' option add the following:
case 'email':
//includes email form
require( dirname(__FILE__).'/_email.php');
break;
Next create the file /skins/<skin name>/_email.php and open it up in a text editor. Paste the following code into it:
<?
//Check page isn't being accessed directly
if( !defined('DB_USER') ) die( 'Please, do not access this page directly.' );
//Check if form is submitted
if(isset($_POST['submit'])){
//Variablise details
$to = ''; //Your email address goes here
$subject = ''; //Your subject goes here
$message = $_POST['message'] . "\n\n" . $_POST['name'];
$headers = 'From:' . $_POST['email'] . '\r\n';
//Email details
mail($to, $subject, $message, $headers);
//Show thank you message
?>
<div class="bPost">
<h2>Contact</h2>
<p>Thank you. Your message has been sent and I will
endeavour to reply to you as soon as I can.</p>
</div>
<?
}
else{
//Show email form
?>
<div class="bPost">
<h2>Contact</h2>
<p>Send me your thoughts, ideas, opinions, praise and criticism
direct to my inbox by filling in the form below. All correspondence
is always appreciated.</p>
<form method="post" action="<?=$_SERVER['PHP_SELF']?>?disp=email">
<p>
<label for="name">Name:</label>
<br />
<input name="name" id="name" type="text" size="20" />
</p>
<p>
<label for="email">Email:</label>
<br />
<input name="email" id="email" type="text" size="20" />
</p>
<p>
<label for="message">Message:</label>
<br />
<textarea name="message" id="message" type="text" rows="10" cols="50"></textarea>
</p>
<p>
<input name="submit" id="submit" type="submit" value="Send message" />
</p>
</form>
</div>
<?
}
?>
Finally, create a link to the page (http://www.yourdomainname.com/index.php?disp=email)
Job Done!
I know its very basic and can be improved immensley but I needed something quick. I'll add error checking etc. later. If anyone wants to post improvements, please go ahead.
Once again, Thank You.
Arkad
Works just fine
I'm customising it to my particular fields and requirements and adding a quick and nasty JS validation script.
Will see what I can drum up for an inline validator unless you come up with one.
Gets rid of my existing and separate xhtml form page.
Thanks Arkad
Instead of doing $_POST['message'] etc use param( 'message', 'string' ) it's far more secure ;)
¥
Can you give a copy of that ¥åßßå , relevent to the above code
I'm also anxious about security
It'd look something like this :-
<?php
//Check page isn't being accessed directly
if( !defined('DB_USER') ) die( 'Please, do not access this page directly.' );
//Check if form is submitted
param( 'the_action', 'string' );
if ( $the_action == 'send' )
{
param( 'message', 'string' );
param( 'name', 'string' );
param( 'email', 'string' );
//Variablise details
$to = ''; //Your email address goes here
$subject = ''; //Your subject goes here
$message .= "\r\n".$name;
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'From: '.$email."\r\n";
$headers .= 'Reply-To: '.email."\r\n" ;
//Email details
if ( @mail($to, $subject, $message, $headers) )
{
//Show thank you message
?>
<div class="bPost">
<p>Thank you. Your message has been sent and I will
endeavour to reply to you as soon as I can.</p>
</div>
<?php
}else{
// show error message
?>
<div class="bPost">
<p>Sorry, your message could not be sent at this time, please try again later</p>
</div>
<?php
}
} else {
//Show email form
?>
<div class="bPost">
<h2>Contact</h2>
<p>Send me your thoughts, ideas, opinions, praise and criticism
direct to my inbox by filling in the form below. All correspondence
is always appreciated.</p>
<form method="post" action="<?php echo $Blog->siteurl; ?>">
<div>
<input type="hidden" name="disp" value="email" />
<input type="hidden" name="the_action" value="send" />
<p><label for="name">Name:</label>
<br />
<input name="name" id="name" type="text" size="20" />
</p>
<p>
<label for="email">Email:</label>
<br />
<input name="email" id="email" type="text" size="20" />
</p>
<p>
<label for="message">Message:</label>
<br />
<textarea name="message" id="message" type="text" rows="10" cols="50"></textarea>
</p>
<p>
<input name="submit" id="submit" type="submit" value="Send message" />
</p>
</div>
</form>
</div>
<?php
}
?>
¥
Thanks mate :)
No problem ;)
¥
This feature is already in b2evolution 1.8, which hasn't quite been released yet, but I'm running it [url=http://adrianmochamber.com/]here[/url]. Go to that page and click on the link in the grey box that says "Contact us". Here are some options for you that might be easier than hacking your 0.9.0.12 install:
a. Uprgrade to 1.6-alpha (I'm pretty sure that it also has this feature).
b. Upraged to 1.8-cvs
c. Wait a few more weeks until 1.8-alpha is released