Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: PHP Code Help

  1. #1
    New to the CF scene
    Join Date
    Mar 2014
    Location
    Philippines
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    PHP Code Help

    Greetings,

    We have purchased a wordpress template and we needed to add some fields to the booking form. The creator told me that we I have to manually add the code. What I have decided to add is some Radio Button choices. I have attached two screenshots of the booking form. The first one is what it looks like currently, the second one is what I wanted it to look like.

    Here is the screenshot of the booking form:
    PHP Code Help-booking-form-target.jpgPHP Code Help-booking-form-current.jpg


    Here is the PHP Code of the booking form:
    PHP Code:
    <?php

    /**

    * Template Name: Reservation

    *

    */

    ?>

    <?php

        

        $de_data 
    get_option'theme_mods_vierra' ); 

        
    $de_email = isset($de_data ['DE_email_contact']) ? $de_data ['DE_email_contact'] : null;

        
    $success_message  = isset($de_data ['DE_booking_success_message']) ? $de_data ['DE_booking_success_message'] : null;

        
    $DE_mail_wrapper_color  = isset($de_data ['DE_mail_wrapper_color']) ? $de_data ['DE_mail_wrapper_color'] : null;

        
    $DE_mail_header_color  = isset($de_data ['DE_mail_header_color']) ? $de_data ['DE_mail_header_color'] : null;

        
    $DE_mail_header_font_color  = isset($de_data ['DE_mail_header_font_color']) ? $de_data ['DE_mail_header_font_color'] : null;

        
    $DE_mail_header_text  = isset($de_data ['DE_mail_header_text']) ? $de_data ['DE_mail_header_text'] : null;

        
    $DE_mail_body_color_2  = isset($de_data ['DE_mail_body_color_2']) ? $de_data ['DE_mail_body_color_2'] : null;

        
    $DE_mail_body_color_1  = isset($de_data ['DE_mail_body_color_1']) ? $de_data ['DE_mail_body_color_1'] : null;

        
    $DE_mail_body_font_color  = isset($de_data ['DE_mail_body_font_color']) ? $de_data ['DE_mail_body_font_color'] : null;

        
    $DE_mail_footer_color  = isset($de_data ['DE_mail_footer_color']) ? $de_data ['DE_mail_footer_color'] : null;

        
    $DE_mail_footer_font_color  = isset($de_data ['DE_mail_footer_font_color']) ? $de_data ['DE_mail_footer_font_color'] : null;

        
    $DE_mail_footer_text  = isset($de_data ['DE_mail_footer_text']) ? $de_data ['DE_mail_footer_text'] : null;



    ?>

    <?php 



    //If the form is submitted

    if(isset($_POST['submitted'])) {

        

        

        
    // required field

        
    if(trim($_POST['datepick1']) === '') {

            
    $datepick1Error =  'Please check again!'

            
    $hasError true;

        } else {

            
    $datepick1 trim($_POST['datepick1']);

        }

        

        
    // required field

        
    if(trim($_POST['datepick2']) === '') {

            
    $datepick2Error =  'Please check again!'

            
    $hasError true;

        } else {

            
    $datepick2 trim($_POST['datepick2']);

        }

        

        
    // required field

        
    if(trim($_POST['contactName']) === '') {

            
    $contactNameError =  'Please check again!'

            
    $hasError true;

        } else {

            
    $contactName trim($_POST['contactName']);

        }

        

        
    // required field

        
    if(trim($_POST['person_num']) === '') {

            
    $person_numError =  'Please check again!'

            
    $hasError true;

        } else {

            
    $person_num trim($_POST['person_num']);

        }



        

        
    // required field

        
    if(trim($_POST['phone']) === '') {

            
    $phoneError =  'Please check again!'

            
    $hasError true;

        } else {

            
    $phone trim($_POST['phone']);

        }

        

            

        
    // need valid email

        
    if(trim($_POST['email']) === '')  {

            
    $emailError 'Forgot to enter in your e-mail address.';

            
    $hasError true;

        } else if (!
    preg_match("/^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$/i"trim($_POST['email']))) {

            
    $emailError 'You entered an invalid email address.';

            
    $hasError true;

        } else {

            
    $email trim($_POST['email']);

        }

        

        
    $room_type $_POST['my_select_1'];

        

        
    $comment trim($_POST['comment']);

            

        
    // upon no failure errors let's email now!

        
    if(!isset($hasError)) {

            

            
    $emailTo =  $de_email;

            
    $subject $DE_mail_header_text;

            
    $sendCopy trim($_POST['sendCopy']);

            
    $body "

            <html>

    <body>

    <div style='padding:12px; display:inline-block; background:"
    .$DE_mail_wrapper_color."'>

    <div style='width:300; padding:10px; font-family:Arial, Helvetica, sans-serif; text-align:center; background:"
    .$DE_mail_header_color."; color:".$DE_mail_header_font_color."; font-weight:bold;'>".$DE_mail_header_text."</div>

    <div style=' display:inline-block; font-family:Arial, Helvetica, sans-serif;'>

    <table width='320' cellpadding='0' cellspacing='0' border='0' style=' color:"
    .$DE_mail_body_font_color."'>

      <tr>

        <td valign='top' style='padding:8px 8px 8px 10px;' bgcolor='"
    .$DE_mail_body_color_1."'><strong>Room Type</strong></td>

        <td valign='top' style='padding:8px 8px 8px 10px;' bgcolor='"
    .$DE_mail_body_color_1."'>$room_type</td>

      </tr>
      
      <tr>

        <td valign='top' style='padding:8px 8px 8px 10px;' bgcolor='"
    .$DE_mail_body_color_1."'><strong>Shuttle Service</strong></td>

        <td valign='top' style='padding:8px 8px 8px 10px;' bgcolor='"
    .$DE_mail_body_color_1."'>$shuttleService</td>

      </tr>
      
      <tr>

        <td valign='top' style='padding:8px 8px 8px 10px;' bgcolor='"
    .$DE_mail_body_color_1."'><strong>Breakfast in Bed</strong></td>

        <td valign='top' style='padding:8px 8px 8px 10px;' bgcolor='"
    .$DE_mail_body_color_1."'>$breakfast</td>

      </tr>

      <tr>

        <td valign='top' style='padding:8px 8px 8px 10px;' bgcolor='"
    .$DE_mail_body_color_2."'><strong>Check In Date</strong></td>

        <td valign='top' style='padding:8px 8px 8px 10px;' bgcolor='"
    .$DE_mail_body_color_2."'>$datepick1</td>

      </tr>

      <tr>

        <td valign='top' style='padding:8px 8px 8px 10px;' bgcolor='"
    .$DE_mail_body_color_1."'><strong>Check In Date</strong></td>

        <td valign='top' style='padding:8px 8px 8px 10px;' bgcolor='"
    .$DE_mail_body_color_1."'>$datepick2</td>

      </tr>  
      
      <tr>

        <td valign='top' style='padding:8px 8px 8px 10px;' bgcolor='"
    .$DE_mail_body_color_2."'><strong>Name</strong></td>

        <td valign='top' style='padding:8px 8px 8px 10px;' bgcolor='"
    .$DE_mail_body_color_2."'>$contactName</td>

      </tr>

      <tr>

        <td valign='top' style='padding:8px 8px 8px 10px;' bgcolor='"
    .$DE_mail_body_color_1."'><strong>Email</strong></td>

        <td valign='top' style='padding:8px 8px 8px 10px;' bgcolor='"
    .$DE_mail_body_color_1."'>$email</td>

      </tr>

      <tr>

        <td valign='top' style='padding:8px 8px 8px 10px;' bgcolor='"
    .$DE_mail_body_color_2."'><strong>Phone</strong></td>

        <td valign='top' style='padding:8px 8px 8px 10px;' bgcolor='"
    .$DE_mail_body_color_2."'>$phone</td>

      </tr>

      <tr>

        <td valign='top' style='padding:8px 8px 8px 10px;' bgcolor='"
    .$DE_mail_body_color_1."'><strong>Person</strong></td>

        <td valign='top' style='padding:8px 8px 8px 10px;' bgcolor='"
    .$DE_mail_body_color_1."'>$person_num</td>

      </tr>



      <tr>

        <td valign='top' style='padding:8px 8px 8px 10px;' bgcolor='"
    .$DE_mail_body_color_2."'><strong>Comments</strong></td>

        <td valign='top' style='padding:8px 8px 8px 10px;' bgcolor='"
    .$DE_mail_body_color_2."'>$comment</td>

      </tr>

       <tr>

        <td colspan='2' valign='top' style='padding:10px; color:"
    .$DE_mail_footer_font_color."; font-style:italic; text-align:center;' bgcolor='".$DE_mail_footer_color."'><strong>".$DE_mail_footer_text."</strong></td>

      </tr>

    </table>

    </div>

    </div>

    </body>

    "
    ;

                
    $headers 'MIME-Version: 1.0' "\r\n";

                
    $headers .= 'Content-type: text/html; charset=iso-8859-1' "\r\n";

                
    $headers .= 'From:'.$contactName.' <'.$emailTo.'>' "\r\n" 'Reply-To: ' $email ."\r\n" "Cc: ".$email;



            
    mail($emailTo$subject$body$headers);

            

            
    // set our boolean completion value to TRUE

            
    $emailSent true;

        }

    }

    ?>





    <?php get_header(); ?>

        <?php $sb get_post_meta($post->ID'my_select_1'true); ?>

        <?php $btn_visit get_option('DE_btn_view '); ?>

           <?php $btn_more_images get_option('DE_btn_more_images');?>



        <?php if (have_posts()) : while (have_posts()) : the_post(); ?>

             <div id="content-wrapper" class="no-bg">

            <div class="container">

                <div class="row">

                <!-- ********** menu image *********** -->

                 <?php if($sb=="None"){

                     echo 
    '<div class="span12">';

                     }else{

                     echo 
    '<div class="span8">';     

                 }
    ?>

                    <div id="booking-form-main" class="booking-form">

                        <form id="contact-us" action='<?php the_permalink(); ?>' method="post">

                        <?php if(isset($hasError) || isset($captchaError) ) { ?>

                            <p class="span6 email-alert"><?php echo __('Error submitting the form','Vierra'); ?></p>

                        <?php ?>

                        

                        <div class="booking-inner row">

                            

                        <div class="span6">

                                

                                <span class="text-label"><i class="icon-bookmark"></i><?php echo __('Select Room','Vierra'); ?></span>

                                <select name="my_select_1" id="my_select_1">

                                    <?php

                                                $paged 
    get_query_var('paged') ? get_query_var('paged') : 1;

                                                
    $wp_query = new WP_Query(array(    'post_type' => 'room','paged' => $paged));

                                                

                                                if (
    have_posts()) : while (have_posts()) : the_post(); ?>

                                                                <option>

                                                                    <?php the_title(); ?>

                                                                </option>

                                                                

                                                                <?php         endwhile;endif;     ?>

                                                                <?php wp_reset_query(); ?> 

                                                                </select>

                                

                                

                            </div>

                            

                            <div class="clearfix"></div>

                            

                              <div class="span3">

                                <span class="text-label"><i class="icon-calendar"></i><?php echo __('Check In Date','Vierra'); ?></span>

                                <input type="text" name="datepick1" id="datepick1" value="<?php if(isset($_POST['datepick1']))  echo $_POST['datepick1'];?>" class="requiredField" />

                              </div>

                            

                            <div class="span3">

                                <span class="text-label"><i class="icon-calendar"></i><?php echo __('Check Out Date','Vierra'); ?></span>

                                <input type="text" name="datepick2" id="datepick2" value="<?php if(isset($_POST['datepick2']))  echo $_POST['datepick2'];?>" class="requiredField" />

                            </div>
                            
                            
                            
                            <div class="clearfix"></div>

                          

                            <div class="span6">

                                <span class="text-label"><i class="icon-bookmark"></i><?php echo __('Shuttle Service (P500 Charge from the Airport)','Vierra'); ?></span>
                                <input type="radio" name="shuttleService" <?php if (isset($shuttleService) && $shuttleService=="yes") echo "checked";?> value="yes">Yes
                                <input type="radio" name="shuttleService" <?php if (isset($shuttleService) && $shuttleService=="no") echo "checked";?>value="no">No

                                 </div>
                            
                            
                            
                            <div class="clearfix"></div>

                          

                            <div class="span6">

                                <span class="text-label"><i class="icon-bookmark"></i><?php echo __('Breakfast in Bed (Local and International Meals. P500 per person per day)','Vierra'); ?></span>
                                <input type="radio" name="breakfast" <?php if (isset($breakfast) && $breakfast=="yes") echo "checked";?> value="yes">Yes
                                <input type="radio" name="breakfast" <?php if (isset($breakfast) && $breakfast=="no") echo "checked";?>value="no">No

                                 </div>

                            

                              <div class="clearfix"></div>

                          

                            <div class="span3">

                                <span class="text-label"><i class="icon-user"></i><?php echo __('Name','Vierra'); ?></span>

                                  <input type="text" name="contactName" id="contactName" value="<?php if(isset($_POST['contactName'])) echo $_POST['contactName'];?>" class="requiredField" />

                                  <?php if($nameError != '') { ?>

                                  <span class="error"></span>

                                  <?php ?>

                                 </div>

                            

                            <div class="span3">

                                <span class="text-label"><i class="icon-group"></i><?php echo __('Number of Person','Vierra'); ?></span>

                                <input type="text" name="person_num" id="person_num" value="<?php if(isset($_POST['person_num']))  echo $_POST['person_num'];?>" class="requiredField" />

                                  <?php if($countError != '') { ?>

                                  <span class="error"></span>

                                  <?php ?>

                            </div>

                            <div class="clearfix"></div>

                            <div class="span3">

                                <span class="text-label"><i class="icon-envelope"></i><?php echo __('Email','Vierra'); ?></span>

                                  <input type="text" name="email" id="email" value="<?php if(isset($_POST['email']))  echo $_POST['email'];?>" class="requiredField email" />

                                      <?php if($emailError != '') { ?>

                                      <span class="error"></span>

                                      <?php ?>

                            </div>

                            

                            <div class="span3">

                                <span class="text-label"><i class="icon-phone"></i><?php echo __('Phone','Vierra'); ?></span>

                                <input type="text" name="phone" id="phone" value="<?php if(isset($_POST['phone'])) echo $_POST['phone'];?>" class="requiredField" />

                                      <?php if($phoneError != '') { ?>

                                      <span class="error"></span>

                                      <?php ?>

                            </div>

                            

                            <div class="clearfix"></div>

                            

                            <div class="span6">

                                <span class="text-label"><i class="icon-comment"></i><?php echo __('Comment','Vierra'); ?></span>

                                <textarea name="comment" id="comment" value="<?php if(isset($_POST['comment'])) echo $_POST['comment'];?>"></textarea>

                            </div>



                            

                            <div class="clearfix"></div>

                            

                            

                            <div class="span3">

                                <button name="submit" type="submit" class="btn btn-primary btn-large"><?php echo __('Book Now','Vierra'); ?></button>

                                <input type="hidden" name="submitted" id="submitted" value="true" />

                            </div>

                            

                      </div>

                           <div class="clearfix"></div>

                        </form>

                        

                        

                        

                    </div>

                

                    <?php the_post_thumbnail('full'); ?>

                </div>

               

                <?php if($sb!="None"){

                 echo 
    '<div class="span4"><div class="sb inner">';    

                    
    dynamic_sidebar$sb );

                 echo 
    '</div></div>' ;

                 }
    ?>

                </div>

                </div>

            </div>



            <!-- ********** custom bg *********** -->

            <div id="background-image">

            <script>

             jQuery.backstretch("<?php echo wp_get_attachment_urlget_post_thumbnail_id($post->ID) ); ?>");

             jQuery('#bg-page').hide();

            </script>

            </div>

        <?php endwhile; endif;?>



    <script type="text/javascript">

        <!--//--><![CDATA[//><!--

        jQuery(document).ready(function() {

            jQuery('form#contact-us').submit(function() {

                jQuery('form#contact-us .error').remove();

                var hasError = false;

                jQuery('.requiredField').each(function() {

                    if(jQuery.trim(jQuery(this).val()) == '') {

                        var labelText = jQuery(this).prev('label').text();

                        //jQuery(this).parent().append('<span class="error">Your forgot to enter your '+labelText+'.</span>');

                        jQuery(this).addClass('inputError');

                        hasError = true;

                    } else if(jQuery(this).hasClass('email')) {

                        var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;

                        if(!emailReg.test($.trim(jQuery(this).val()))) {

                            var labelText = jQuery(this).prev('label').text();

                            jQuery(this).parent().append('<span class="error">Sorry! You\'ve entered an invalid '+labelText+'.</span>');

                            jQuery(this).addClass('inputError');

                            hasError = true;

                        } else{

                        jQuery(this).removeClass('inputError');

                    }

                    } else{

                        jQuery(this).removeClass('inputError');

                    }

                });

                if(!hasError) {

                    var formInput = jQuery(this).serialize();

                    jQuery.post(jQuery(this).attr('action'),formInput, function(data){

                        jQuery('form#contact-us').slideUp("fast", function() {                   

                            jQuery(this).before('<p class="tick"><?php echo __("Thank You! You will get confirmation shortly.","Vierra"); ?></p>');

                        });

                    });

                }

                

                return false;    

            });

            

            jQuery('.inputError').focus(function() { 

            jQuery('this').val('yeah'); 

            });

        });

        

        

        //-->!]]>

    </script>



    <?php get_footer(); ?>
    Here is the CSS of the booking form just in case:
    Code:
    /*-------------------------------------------------- 
    
    /* booking
    
    /*-------------------------------------------------- */
    
    #booking-form-main{
    
    	display:block;
    
    }
    
    
    
    .booking-form{
    
    	background:url(../images/dotwhite75.png);
    
    	padding:30px 0 30px 0;
    
    	text-align:center;
    
    	margin-bottom:30px;
    
    	display:none;
    
    }
    
    
    
    
    
    .booking-form .text-label{
    
    	padding-bottom:10px;
    
    	display:block;
    
    }
    
    
    
    
    
    .booking-form input{
    
    	width:97%;
    
    	border:solid 1px #bbb;
    
    }
    
    
    
    .booking-form textarea{
    
    	width:98%; height:120px;
    
    }
    
    
    
    .booking-form select{
    
    	width:102%;
    
    }
    
    
    
    .booking-form .span3{
    
    }
    
    
    
    .booking-form i{
    
    	margin-right:8px;
    
    	color:#6a4a3d;
    
    }
    
    
    
    .btn-book-submit{
    
    	margin-top:30px;
    
    }
    
    
    
    .booking-inner{
    
    	display:inline-block;
    
    	text-align:left;
    
    }
    
    
    
    #btn-book-now {
    
    	margin-bottom:30px;
    
    }
    
    #btn-book-now .off{
    
    	display:none;
    
    }
    I would really appreciate any help that you would give me

  • #2
    New to the CF scene
    Join Date
    Mar 2014
    Location
    Philippines
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    any help please?

  • #3
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,309
    Thanks
    58
    Thanked 525 Times in 512 Posts
    Blog Entries
    5
    What you're asking isn't a code fix, glitch or bug which we deal with here in the php forum. What you're asking for is a modification / rewrite of your template - from php to html. Thats a project / job and should really go into that forum instead.

    The mods won't move this topic there (they're gentle giants) but at the same time you're unlikely to find the help you want in this forum for free. You really need to advertise it as a job with some sort of reward to get further assistance.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •