logo-dw

Go Back   Dreamweaver Club Forums > Dreamweaver forums > Dreamweaver General
Register FAQ Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
Old 07-21-2014, 02:07 PM   #1
Pieter Nel
 
Join Date: Jul 2014
Posts: 3
Red face Novice needs help please

Hi-I am new to php. I need to add check boxes to my php file to send options. I have added it to the html but idon't have a clue what to add to the php in order to recieve the correct info via email.
Here is the HTML:

HTML Code:
<form action="sendmail.php" method="post" class="form-contact" id="form-contact">
           
            <p>
                <label for="name"><span>Name</span></label>
                <input type="text" name="name" id="name" class="col01" />
                
                <label for="email"><span>Email</span></label>
                <input type="text" name="email" id="email" class="col01" />
                
                <label for="phone"><span>Phone Number</span></label>
                <input type="text" name="phone" id="phone" class="col01"/>  
                
                <label for="event" accesskey="S">Type of Event</label>
                <select name="event" id="event">
                  <option value="pselect">- Select -</option>
                  <option value="Wedding">Wedding</option>
                  <option value="Birthday ">Birthday</option>
                  <option value="Corporate">Corporate</option>
                  <option value="Other">Other</option>
                </select>
                
                
                <label for="date"><span>When is your Event?</span></label>
                <input type="text" name="date" id="date" class="col01"/>
                
                <label for="venue"><span>Where is your Event?</span></label>
                <input type="text" name="venue" id="venue" class="col01"/>
                
                <label for="guests"><span>For how many Guests?</span></label>
                <input type="text" name="guests" id="guests" class="col01"/>
                
                <label for="package" accesskey="S">Please choose your Package</label>
                <select name="package" id="package">
                  <option value="pselect">- Select -</option>
                  <option value="2 hours R3450">2 hours R3450</option>
                  <option value="3 hours R3950">3 hours R3950</option>
                  <option value="4 hours R4500">4 hours R4500</option>
                  <option value="More than 4 hours">More than 4 hours</option>
                </select>
            </p> 
            <label for="extra"><span>Will you be needing any additional services?</span></label><br />
      <input name="additional services[]" type="checkbox" class="form-contact" id="CheckboxGroup1_0" value="Fridge Magnet" />
      Fridge Magnet
   
      <input name="additional services[]" type="checkbox" class="form-contact" id="CheckboxGroup1_1" value="Guestbook" />
      Guest Book   
    <label for="message"><span><br />
      Anything else you would like us to know?</span></label>
              <textarea cols="30" rows="8" name="message" id="message" class="col01"></textarea>
              
              <input type="hidden" name="action" value="send">
              
            </p>
  <p class="cf-sb">
                <input type="submit" name="sendbutton" id="sendbutton" class="sendbutton" value="Send" />
            </p>
          </form>
and here is the PHP
PHP Code:
<?php

/**
 * Define the email witch send the email written by the user
 */ 
define('TO''me@gmail.com'); 

/**
 * Define the from email
 */ 
define('FROM''noreply@email.com'); 

/**
 * define the body of the email. You can add some shortcode, with this format: %ID%
 * 
 * ID = the id have you insert on the html markup.
 * 
 * e.g.
 * <input type="text" name="email" />
 *       
 * You can add on BODY, this:
 * email: %email%   
 */ 
define('BODY''Hi you have a Photobooth query from:<br /><strong> %name% </strong><br />
email: %email% <br />
Phone no: <strong>%phone% </strong><br />
Event Type: <strong>%event% </strong>on <strong>%date%</strong> for <strong>%guests%</strong> guests at <strong>%venue%</strong> <br />
Package Selected: <strong>%package%</strong> <br />
Extras Required: <strong>%CheckboxGroup1_0%</strong> <br />
<br />
<strong>Message: </strong><br /> %message%'
);
    
// NO NEED EDIT
function sendemail() 
{
    if ( isset( 
$_POST['action'] ) AND $_POST['action'] == 'send' 
    {
        
$body BODY;
        
        if( !
is_string$_POST['name'] ) OR $_POST['name'] == '' )
            return 
'<p class="error">Insert correct name</p>';
        
        if( !
is_email$_POST['email'] ) OR $_POST['email'] == '' 
            return 
'<p class="error">Insert correct email</p>';
          
        
$subject $_POST['subject'];
        
        if( !
is_email$subject ) OR $subject == '' )
            
$subject 'Website Response.';
        
        foreach( 
array_map'stripslashes'$_POST ) as $id => $var )
        {
            if( 
$id == 'message' $var nl2br($var);
            
$body str_replace"%$id%"$var$body );    
        }
        
        
        
$headers  'MIME-Version: 1.0' "\r\n";
        
$headers .= 'Content-type: text/html; charset=UTF-8' "\r\n";
        
$headers .= "From: noreply@booth.co.za\r\n";
    
        
$sendmail mail(TO$subject$body$headers);
             
        if (
$sendmail
            return 
'<p class="success-box">Thank you, We will respond to you shortly.</p>';
    } 
}

function 
is_email($email
{
    if (!
preg_match("/[a-z0-9][_.a-z0-9-]+@([a-z0-9][0-9a-z-]+.)+([a-z]{2,4})/" $email))
    {
        return 
false;
    }
    else
    {
        return 
true;
    }
}                              

echo 
sendemail();  

?>
When the contact form is submitted I get this error:

Warning: stripslashes() expects parameter 1 to be string, array given in /home/photo/public_html/sendmail.php on line 49

I do receive the contact form with all the info required except for the check-box information.

any help will be appreciated
Pieter Nel is offline   Reply With Quote
Old 07-21-2014, 08:32 PM   #2
Ricky55
Ricky55's Avatar
 
Join Date: Oct 2005
Location: West Yorkshire, UK
Posts: 1,855
Default

Looking at the script don't you just add %your-id% and then match this to the id your element.

So for a check box you'd add

Code:
<form>
<input type="checkbox" name="vehicle" value="Bike" id="bike">I have a bike<br>
<input type="checkbox" name="vehicle" value="Car" id="car">I have a car
</form>
Code:
I have a bike: <strong>%bike%</strong>
I have a car: <strong>%car%</strong>
__________________
Qwerty Design

Check out my blog for web design insights.
http://www.qwerty-design.co.uk/
Follow me on Twitter: @QwertyDesignUK
Ricky55 is offline   Reply With Quote
Old 07-21-2014, 08:41 PM   #3
Ricky55
Ricky55's Avatar
 
Join Date: Oct 2005
Location: West Yorkshire, UK
Posts: 1,855
Default

does work like that. Working fine on my server.

http://www.qwerty-demos.co.uk/test.html
__________________
Qwerty Design

Check out my blog for web design insights.
http://www.qwerty-design.co.uk/
Follow me on Twitter: @QwertyDesignUK
Ricky55 is offline   Reply With Quote
Old 07-22-2014, 07:07 AM   #4
Pieter Nel
 
Join Date: Jul 2014
Posts: 3
Default

Thanks Ricky - I have changed the html as follows:
<input type="checkbox" name="extra" value="Fridge Magnet" id="magnet">Fridge Magnet<br>
<input type="checkbox" name="extra" value="Guest Book" id="book">Guest Book

and the PHP to include the id:
define('BODY', 'Hi you have a Photobooth query from:<br /><strong> %name% </strong><br />
email: %email% <br />
Phone no: <strong>%phone% </strong><br />
Event Type: <strong>%event% </strong>on <strong>%date%</strong> for <strong>%guests%</strong> guests at <strong>%venue%</strong> <br />
Package Selected: <strong>%package%</strong> <br />
Extras Required: <strong>%magnet% </strong><strong>%book% </strong> <br />
<strong>Message: </strong><br /> %message%');

and the email I receive looks like this:

Event Type: Corporate on 15 December for 22 guests at Durban
Package Selected: More than 4 hours
Extras Required: %magnet%%book%
Message:
nil

so all the other fields are populated using the id tag but not the info relative to the tick boxes

any suggestions?
Pieter Nel is offline   Reply With Quote
Old 07-22-2014, 07:18 AM   #5
Pieter Nel
 
Join Date: Jul 2014
Posts: 3
Red face

Thanks Ricky

I have made your suggestion
HTML Code:
<input type="checkbox" name="extra" value="Fridge Magnet" id="magnet">Fridge Magnet<br>
<input type="checkbox" name="extra" value="Guest Book" id="book">Guest Book
and the php
PHP Code:
Extras Required: <strong>%magnet% </strong><strong>%book% </strong> <br /> 
but the mail i receive:

Phone no: 79992252
Event Type: Corporate on 15 December for 22 guests at Durban
Package Selected: More than 4 hours
Extras Required: %magnet%%book%
does not include the tickbox actual value only the =id, any ideas?
Pieter Nel is offline   Reply With Quote
Old 07-23-2014, 01:29 AM   #6
edbr
edbr's Avatar
 
Join Date: Aug 2005
Location: Bali
Posts: 11,164
Default

try in your form

Code:
<input type="checkbox" name="extra[]" value="Fridge Magnet" id="magnet">Fridge Magnet<br>
<input type="checkbox" name="extra[]" value="Guest Book" id="book">Guest Book
__________________
If you're happy and you know it shake your meds!
different style links examples

Flight / Hotel search
Free script download
Bali Villas
edbr is offline   Reply With Quote
Old 07-23-2014, 09:42 PM   #7
Ricky55
Ricky55's Avatar
 
Join Date: Oct 2005
Location: West Yorkshire, UK
Posts: 1,855
Default

Have you got this sorted?

Seemed to work fine on my server.

Might have something to do with the version of PHP you are running. Not sure TBH.

I have another script if you can't get this one working.

Mail me if you want it richard@qwerty-design.co.uk

Works fine with all types of forms.
__________________
Qwerty Design

Check out my blog for web design insights.
http://www.qwerty-design.co.uk/
Follow me on Twitter: @QwertyDesignUK
Ricky55 is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 09:34 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Copyright 2006 DreamweaverClub.com