Category Archives: Random

PHP Tips: How to send an email through a contact form to multiple recipients

Here is the simple line of code you can use to send a PHP email contact form to multiple email addresses:

  $to = $this->fields['EmailAddress'].',';
	  $to .='info@yourwebsite.com';

This comes in handy when you have to send the email to one specific email address in addition to an email address which is being pulled in via a variable – for example, if you want to send a copy of the email to users themselves, as in the example above.

PHP Tips: How to convert underscores to spaces in emailed contact forms

I was recently building a PHP contact form and ran into the issue where the field names I was using in my HTML form which we were more than one word long (i.e.: “First Name”) were being emailed with underscores in place of the spaces (i.e.: “First_Name”). The PHP file I was processing my form with was replacing the spaces with underscores. Which was necessary for processing the form, BUT – I needed to convert those underscores back to spaces when the contact form data was emailed for usability purposes.

Here is the simple line of code that I added to my PHP file:

$msg = str_replace("_"," ", $msg);

Where $msg was part of my mail function:

 mail($to, $subject, $msg, $headers)

And had already been defined:

  $msg = "User message: \n\n";
          foreach($this->fields as $key => $field)
                $msg .= "$key:  $field \n";

I added the first line of code (which used the str_replace function) right after the code which defined $msg.

You will want to replace the variable $msg in the code above with the name of the variable you are using for the body of the email in your mail function.


					

Javascript: Display a second drop-down menu or div based on user’s selection in first drop-down menu

Here is the Javascript that I use to display a second drop-down menu or a div based on a user’s selection in the first drop-down menu.
Read more …

WordPress Tricks: Add a div or other element to one specific page or page type

 

Here is the code I use to add a div or image or other element to just one page or category page of my WordPress sites:

This code will add a div with the id “featured_content” only on the home page:

<?php if ( is_home() ) { ?>
<div id="featured_content">
&nbsp;
</div>
<?php } ?>

 

This code would add a div with the id “featured_recipe” to all posts in the category “recipes.”:

<?php if ( is_category('recipes') ) { ?>
<div id="featured_recipe">
&nbsp;
</div>
<?php } ?>

 

This code would exclude “myimage.jpg” only on the Contact page:

<?php if ( !is_page('contact') ) { ?>
<img src="myimage.jpg">
<?php } ?>

 

As you can see, there are many uses and ways implementations of this code. Let me know if you have any questions or need further assistance.

WordPress Tricks: How to fix the issue of YouTube videos appearing on top of other content

Here is the code I use to make sure the embedded YouTube videos on a website don’t appear on top of other content (for example: drop down menus):

<object width='400' height='350'> 
    <param name='movie' value='http://www.youtube.com/YOURVIDEOLINK'> 
    <param name='type' value='application/x-shockwave-flash'> 
    <param name='allowfullscreen' value='true'> 
    <param name='allowscriptaccess' value='always'> 
    <param name="wmode" value="opaque" />
    <embed width='400' height='350'
            src='http://www.youtube.com/YOURVDIDEOLINK'
            type='application/x-shockwave-flash'
            allowfullscreen='true'
            allowscriptaccess='always'
            wmode="opaque"
    ></embed> 
    </object>

The areas of code highlighted in red above are what solve the overlapping/z-index problem, so if you already have your video embedded on your site, simply add those sections in the right place in your code and that should solve the issue.

NOTE: I found this solution at http://australiansearchengine.wordpress.com/2010/06/19/youtube-video-css-z-index/

HTML: Add a drop down list of states with links to their respective pages

Here is how to add a drop down list of states with links to each of their respective pages to your web page.

First, add this script to the <head> section of your website:

<SCRIPT LANGUAGE="JavaScript"><!--
function goto_URL(object) {
window.location.href = object.options[object.selectedIndex].value;
}
//--></SCRIPT>

Then build your list of states like this:

<FORM>
<SELECT NAME="selectName" onChange="goto_URL(this.form.selectName)">
<option value="#" selected>Choose Your State...</option>
<option value="/states/alabama.html">Alabama</option>
<option value="/states/alaska.html">Alaska</option>
<option value="/states/arizona.html">Arizona</option>
<option value="/states/arkansas.html">Arkansas</option>
<option value="/states/california.html">California</option>
<option value="/states/colorado.html">Colorado</option>
<option value="/states/connecticut.html">Connecticut</option>
<option value="/states/dc.html">DC</option>
<option value="/states/delaware.html">Delaware</option>
<option value="/states/florida.html">Florida</option>
<option value="/states/georgia.html">Georgia</option>
<option value="/states/guam.html">Guam</option>
<option value="/states/hawaii.html">Hawaii</option>
<option value="/states/idaho.html">Idaho</option>
<option value="/states/illinois.html">Illinois</option>
<option value="/states/indiana.html">Indiana</option>
<option value="/states/iowa.html">Iowa</option>
<option value="/states/kansas.html">Kansas</option>
<option value="/states/kentucky.html">Kentucky</option>
<option value="/states/louisiana.html">Louisiana</option>
<option value="/states/maine.html">Maine</option>
<option value="/states/maryland.html">Maryland</option>
<option value="/states/massachusetts.html">Massachusetts</option>
<option value="/states/michigan.html">Michigan</option>
<option value="/states/minnesota.html">Minnesota</option>
<option value="/states/mississippi.html">Mississippi</option>
<option value="/states/missouri.html">Missouri</option>
<option value="/states/montana.html">Montana</option>
<option value="/states/nebraska.html">Nebraska</option>
<option value="/states/nevada.html">Nevada</option>
<option value="/states/newhampshire.html">New Hampshire</option>
<option value="/states/newjersey.html">New Jersey</option>
<option value="/states/newmexico.html">New Mexico</option>
<option value="/states/newyork.html">New York</option>
<option value="/states/northcarolina.html">North Carolina</option>
<option value="/states/northdakota.html">North Dakota</option>
<option value="/states/ohio.html">Ohio</option>
<option value="/states/oklahoma.html">Oklahoma</option>
<option value="/states/oregon.html">Oregon</option>
<option value="/states/pennsylvania.html">Pennsylvania</option>
<option value="/states/puertorico.html">Puerto Rico</option>
<option value="/states/rhodeisland.html">Rhode Island</option>
<option value="/states/southcarolina.html">South Carolina</option>
<option value="/states/southdakota.html">South Dakota</option>
<option value="/states/tennessee.html">Tennessee</option>
<option value="/states/texas.html">Texas</option>
<option value="/states/utah.html">Utah</option>
<option value="/states/vermont.html">Vermont</option>
<option value="/states/virginia.html">Virginia</option>
<option value="/states/washington.html">Washington</option>
<option value="/states/westvirginia.html">West Virginia</option>
<option value="/states/wisconsin.html">Wisconsin</option>
<option value="/states/wyoming.html">Wyoming</option>
</select></FORM>