mardi 4 août 2015

Email Form Not Sending Message - HTML

I have this email code from a website template that I want to use for my site. The problem is that when I click on the "Send message" button, the form simply refreshes and nothing is sent. If there is any text data in the fields, it simply disappears. I have tried to look at possible solutions from this HTML Email Form Not Sending Message but to no avail.

Form HTML

<form name="sentMessage" id="contactForm" method='post' novalidate action="public_html/bin/contact_me.php">
   <div class="control-group form-group">
      <div class="controls">
         <label>Full Name</label>
         <input type="text" class="form-control" name="name" id="name" placeholder="Full Name" required data-validation-required-message="Please enter your name.">
         <p class="help-block"></p>
      </div>
   </div>
   <div class="row">
      <div class="col-md-6">
         <div class="form-group">
            <label>Email Address</label>
            <input type="email" class="form-control" name="email" id="email" placeholder="Email Address" required data-validation-required-message="Please enter your email address.">
         </div>
      </div>
      <div class="col-md-6">
         <div class="form-group">
            <label>Phone Number</label>
            <input type="tel" class="form-control" name="phone" id="phone" placeholder="Phone Number" required data-validation-required-message="Please enter your phone number.">
         </div>
      </div>
   </div>
   <div class="form-group">
      <label>Subject</label>
      <input type="text" class="form-control" name="subject" id="subject" placeholder="Subject" required data-validation-required-message="Please enter your phone number.">
   </div>
   <div class="form-group">
      <label>Message</label>
      <textarea rows="10" cols="100" class="form-control" name="message" id="message" placeholder="Please Enter Your Message Here..." required data-validation-required-message="Please enter your message" maxlength="999" style="height:150px;"></textarea>
   </div>
   <div id="success"></div>
   <div>
      <button type="submit" class="btn btn-two">Send message</button>                          
      <p><br/></p>
   </div>
</form>

PHP Code

<?php
// check if fields passed are empty
if(empty($_POST['name'])        ||
   empty($_POST['phone'])       ||
   empty($_POST['email'])       ||
   empty($_POST['subject'])         ||
   empty($_POST['message'])         ||
   !filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
   {
    echo "No arguments Provided!";
    return false;
   }

$name = $_POST['name'];
$phone = $_POST['phone'];
$email_address = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];

// create email body and send it    
$to = 'info@mywebsite.com'; // PUT YOUR EMAIL ADDRESS HERE
$email_subject = "$subject"; // EDIT THE EMAIL SUBJECT LINE HERE
$email_body = "You have received a new message from your website's contact form.\n\n"."Here are the details:\n\nName: $name\n\nPhone: $phone\n\nEmail: $email_address\n\nMessage:\n$message";
$headers = "From: noreply@your-domain.com\n";
$headers .= "Reply-To: $email_address"; 
mail($to,$email_subject,$email_body,$headers);
return true;            
?>

Js

$(function() {

    $("input,textarea").jqBootstrapValidation({
        preventSubmit: true,
        submitError: function($form, event, errors) {
            // something to have when submit produces an error ?
            // Not decided if I need it yet
        },
        submitSuccess: function($form, event) {
            event.preventDefault(); // prevent default submit behaviour
            // get values from FORM
            var name = $("input#name").val();
            var phone = $("input#phone").val();
            var email = $("input#email").val();
            var message = $("textarea#message").val();
            var firstName = name; // For Success/Failure Message
            // Check for white space in name for Success/Fail message
            if (firstName.indexOf(' ') >= 0) {
                firstName = name.split(' ').slice(0, -1).join(' ');
            }
            $.ajax({
                url: "./bin/contact_me.php",
                type: "POST",
                data: {
                    name: name,
                    phone: phone,
                    email: email,
                    message: message
                },
                cache: false,
                success: function() {
                    // Success message
                    $('#success').html("<div class='alert alert-success'>");
                    $('#success > .alert-success').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;")
                        .append("</button>");
                    $('#success > .alert-success')
                        .append("<strong>Your message has been sent. </strong>");
                    $('#success > .alert-success')
                        .append('</div>');

                    //clear all fields
                    $('#contactForm').trigger("reset");
                },
                error: function() {
                    // Fail message
                    $('#success').html("<div class='alert alert-danger'>");
                    $('#success > .alert-danger').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;")
                        .append("</button>");
                    $('#success > .alert-danger').append("<strong>Sorry " + firstName + " it seems that my mail server is not responding...</strong> Could you please email me directly to <a href='mailto:me@example.com?Subject=Message_Me from myprogrammingblog.com;>me@example.com</a> ? Sorry for the inconvenience!");
                    $('#success > .alert-danger').append('</div>');
                    //clear all fields
                    $('#contactForm').trigger("reset");
                },
            })
        },
        filter: function() {
            return $(this).is(":visible");
        },
    });

    $("a[data-toggle=\"tab\"]").click(function(e) {
        e.preventDefault();
        $(this).tab("show");
    });
});


/*When clicking on Full hide fail/success boxes */
$('#name').focus(function() {
    $('#success').html('');
});

How do I solve this?

How can I limit the number of images shown per page?

I have a certain number of images that are displaying per page. I want to set a maximum limit for the number of images shown on any page, for example setting a property such that no more than eight are shown. I've written this logic in PHP but I'm still seeing all images showing on any given page, ignoring any limit I set. The code:

$counter = 0;

foreach ($device as $value) {
  $entry = $value;
  echo "<head>";
  echo '<script type="text/javascript">',
           'window.setInterval(function() { ',
           "document.getElementById('$counter').src='/latimage.php?&dev=$entry&random='+new Date().getTime();",
           '},1000)',
       '</script>';
echo "</head>";
echo "<body onLoad='setTimeout('refresh()',1000)'>";
echo "<td>$entry<img id= '$counter'  width='100%'  height='auto'></img></td>";

$counter = $counter + 1;

if ($counter == 4 || $counter == 8) {
    echo " <tr>";
}

Magento 1.9 Logo not being displayed on Shipping PDF

When trying to print a delivery for an order in Magento the logo is not displaying. I have narrowed it down to the following line of code in app/code/core/Mage/Sales/Model/Order/Pdf/Abstract.php line 133 in the insertLogo() method.

$image = Mage::getStoreConfig('system/filesystem/media', $store) . '/sales/store/logo/' . $image;

I can't see that this option is being set anywhere and doesn't appear in the core_config_data table. Any ideas on getting this to work? Have I missed a configuration setting?

Symfony 2 not loading database config file

I'm new to symfony and im following the book with heroku as host, im trying to flush a object to database with doctrine but im getting the following error:

[2015-08-04 05:23:58] request.CRITICAL: Uncaught PHP Exception PDOException: "SQLSTATE[08006] [7] could not connect to server: Connection refused Is the server running on host "127.0.0.1" and accepting TCP/IP connections on port 5432?" at /app/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php line 40 {"exception":"[object] (PDOException(code: 7): SQLSTATE[08006] [7] could not connect to server: Connection refused\n\tIs the server running on host \"127.0.0.1\" and accepting\n\tTCP/IP connections on port 5432? at /app/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:40)"} []

I got my configuration files working (i guess):

 parameters.yml
 database_host: host....
 database_port: 5432
 database_name: ddas1mq8intjqt
 database_user: ymmpjzoqbyokbr
 database_password: password.....
 mailer_transport: smtp
 mailer_host: 127.0.0.1
 mailer_user: null
 mailer_password: null
 secret: ThisTokenIsNotSoSecretChangeIt

and my config.yml:

doctrine:
    dbal:
        driver:   pdo_pgsql
        host:     "%database_host%"
        port:     "%database_port%"
        dbname:   "%database_name%"
        user:     "%database_user%"
        password: "%database_password%"
        charset:  UTF8

I've run the console commands to create the tables from the entity classes and it worked, but creating an object and ->flush seems the problem... don't know if its some server configuration or I've done something wrong.

Thank you

calculate sum of variables in a loop

I have the following task:

I have many equal tables of different people (>500) which contain working hours. The following is a sample:

"table01"

date | hours

"table02"

date | hours "table03"

date | hours .....

I have one table with relationship between tables to "cost-Center":

"table_cost-center"

table01 | 0010

table02 | 0030

table03 | 0020

table04 | 0040

table05 | 0060

......

I have to calculate the sum of hours between date 1 and date 2 of each cost-center in a loop. I need to display each sum of every single cost-center and calculate the total sum of all cost-centers together.

My Idea:

$whours= mysql_query ("SELECT sum(hours) FROM `$cost-center_tabelle[$z]` WHERE `$cost-center_table[$z]`.date BETWEEN '$date2' AND '$date1'

Assigning ID's to fields that are echoed using PHP inside a while loop

I currently have two dropdown menus that a user will select the course and a golfer which will load a scorecard.

What I am trying to do now is when a user enters a value into the "Score" field I want the "points" to be automatically shown ("Points" is a read only input field). To do this I am assuming that I will have to give each table row for score and points a specific ID.

echo "<div class='scorecardTable'>
<table 'id=scorecardTable'>
<tr>
<th>HoleNumber</th>
<th>Par</th>
<th>Stroke Index</th>
<th>Score</th>
<th>Points</th>
</tr>'";

while($row = mysqli_fetch_array($result)) { 
    echo "<tr>";
    echo "<td>" . $row['holeNumber'] . "</td>";
    echo "<td>" . $row['par'] . "</td>";
    echo "<td>" . $row['strokeIndex'] . "</td>";
    echo "<td> <input type='text' maxlength='2' id='score' /></td>";
    echo "<td> <input type='text' id='points' readonly></td>";
    echo "</tr>";
}
echo "</table>";

From the above code I am using PHP to print the information from my database but I was just wondering if anyone would know how to assign a unique ID to each of the score and points input fields so I can apply the calculation to each user input.

utf8 characters wrongly displayed as question marks after conversion to mysqli_query()

My database is latin1_swedish_ci but all the tables which contain foreign characters (german, turkish...) are utf8_general_ci.

Before the upgrade to php 5.6, I used mysql_query("SET CHARACTER SET utf8;");mysql_query("SET NAMES utf8"); before mysql_query() and everything was displayed correctly in my page ( in page header).

After the conversion of all mysql_query(...) to mysqli_query(id,...) and running under php 5.6, all the foreign languages are now scrambled with ? and �. Switching back to php 5.4 does not help. phpMyAdmin displays the mysql database (which has not changed) correctly.

I have looked around for a solution but nothing works... am I missing something?

What do I need to change in my code to work properly?