0

i have multiple input form for renting cars, one field is not working and i have no idea why.

Input that is not working is name="fd-phone" one.

Mailer is controller by 3 files, here is eselected code for each. First file is actual html where form is located:

<form action="#" class="form-delivery">
                    <div class="row">
                        <div class="col-md-6">
                            <div class="form-group">
                                <input name="fd-name" id="fd-name" title="Name is required" data-toggle="tooltip"
                                        class="form-control alt" type="text" placeholder="Meno a Priezvisko:*">
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <input name="fd-name" id="fd-email" title="Email is required" data-toggle="tooltip"
                                        class="form-control alt" type="text" placeholder="Email:*">
                            </div>
                        </div>

                        <div class="col-md-6">
                            <div class="form-group">
                                <input name="fd-phone" id="fd-phone" title="Phone is required" data-toggle="tooltip"
                                        class="form-control alt" type="text" placeholder="Telefon:*">
                            </div>
                        </div>


                        <div class="col-md-6">
                            <div class="form-group"><input class="form-control alt" type="text" placeholder="X:"></div>
                        </div>
                    </div>
                </form>

Next file is php mailer of said form, here are parts of code that control form and fd-phone variable:

if ((isset($_POST['fdphone'])) && (strlen(trim($_POST['fdphone'])) > 0)) {
    $fdphone = stripslashes(strip_tags($_POST['fdphone']));
} else {
    $fdphone = 'No phone entered';
}

Table in same php file:

<table width="550" border="0" cellspacing="0" cellpadding="15">
    <tr bgcolor="#eeffee">
        <td>Meno</td>
        <td><?php echo $fdmrms; ?> <?php echo $fdname; ?></td>
    </tr>
    <tr bgcolor="#eeeeff">
        <td>Email</td>
        <td><?php echo $fdemail; ?></td>
    </tr>
    <tr bgcolor="#eeeeff">
        <td>Telefón</td>
        <td><?php echo $fdphone; ?></td>
    </tr>

    <tr bgcolor="#eeffee">
        <td>Správa</td>
        <td><?php echo $fadmessage; ?></td>
    </tr>
    <tr bgcolor="#eeeeff">
        <td>Možnosť platby</td>
        <td><?php echo $po; ?></td>
    </tr>
    <tr bgcolor="#eeffee">
        <td>Extra</td>
        <td><?php echo $extras; ?></td>
    </tr>
</table>

And actual mailer in same file:

require("phpmailer.php");

$mail = new PHPMailer();

$mail->From = $fdemail;
$mail->FromName = $name;
$mail->AddAddress($to, $toname); // Put your email
//$mail->AddAddress($anotheraddress,$anothername); // addresses here

$mail->WordWrap = 50;
$mail->IsHTML(true);

$mail->Subject = "Objednávka z webu Kristof Cars";
$mail->Body = $body;
$mail->AltBody = $message;

Last thing that controls it is .js file and i belive it here where the problem is but i dont know where. Because when i sent form to email, i see telephone input there, but with text that No phone entered even if i write numbers there, so variable should be working but it ignores the input i enter.

Here is .js file code for this form fdphone is the third variable that is in question there, i also added it into datastring below so i dont know why its not sending said input:

$(function () {

    $(".form-additional .form-control, .form-delivery .form-control").tooltip({placement: 'top', trigger: 'manual'}).tooltip('hide');
    $('.form-additional .form-control, .form-delivery .form-control').blur(function () {
        $(this).tooltip({placement: 'top', trigger: 'manual'}).tooltip('hide');
    });

    //$(window).load(function () {});

    // ON CLICK
    $(".reservation-now .btn-reservation-now").click(function () {
        // validate and process form
        // first hide any error messages
        //$('.form-subscribe .error').hide();

        // Extras & Frees
        var counter = 1;
        var fdextras = '';
        var fdcheckbox = $(".form-extras .checkbox");
        $(fdcheckbox).each(function(index, value){
            if($(this).find('input').is(':checked')){
                //fdmrms = $(this).find('input').attr('value');
                //console.log($(this).find('input').next('label').text());
                fdextras = fdextras + ' extra' + counter + '=' + $(this).find('input').next('label').text();
                counter++;
            }
        });

        // Customer information
        var fdmrms = '';
        var fdradio = $(".form-delivery .radio");
        $(fdradio).each(function(index, value){
            if($(this).find('input').is(':checked')){
                //console.log($(this).find('input').attr('value'));
                fdmrms = $(this).find('input').attr('value');
            }
        });

        var fdname = $(".form-delivery input#fd-name").val();
        if (fdname == "" || fdname == "Name..." || fdname == "Name" || fdname == "Name *" || fdname == "Type Your Name...") {
            $(".form-delivery input#fd-name").tooltip({placement: 'top', trigger: 'manual'}).tooltip('show');
            $(".form-delivery input#fd-name").focus();
            return false;
        }


        var fdphone = $(".form-delivery input#fd-phone").val();
        if (fdphone == "" || fdname == "Telefón") {
            $(".form-delivery input#fd-phone").tooltip({placement: 'top', trigger: 'manual'}).tooltip('show');
            $(".form-delivery input#fd-phone").focus();
            return false;
        }





        var fdemail = $(".form-delivery input#fd-email").val();
        var filter = /^[a-zA-Z0-9]+[a-zA-Z0-9_.-]+[a-zA-Z0-9_-]+@[a-zA-Z0-9]+[a-zA-Z0-9.-]+[a-zA-Z0-9]+.[a-z]{2,4}$/;
        //console.log(filter.test(email));
        if (!filter.test(fdemail)) {
            $(".form-delivery input#fd-email").tooltip({placement: 'top', trigger: 'manual'}).tooltip('show');
            $(".form-delivery input#fd-email").focus();
            return false;
        }

        // Payments options
        var po = '';
        var popanel = $(".payments-options .panel");
        $(popanel).each(function(index, value){
            if($(this).find('.panel-title a').attr('aria-expanded') == 'true'){
                //console.log($(this).find('.panel-title a').text());
                po = $(this).find('.panel-title a').text();
                po = po.trim();
            }
        });

        // Addition Information
        var fadmessage = $(".form-additional textarea#fad-message").val();
        if (fadmessage == "" || fdname == "Addition Information") {
            $(".form-additional textarea#fad-message").tooltip({placement: 'top', trigger: 'manual'}).tooltip('show');
            $(".form-additional textarea#fad-message").focus();
            return false;
        }

        // Check if Accept is checked
        var accept = $("#accept");
        if(!accept.is(':checked')){
            $(accept).focus();
            $(accept).parent().find('label').css('color', 'red');
            return false;
        }

        var dataString = 'extras=' + fdextras + '' + '&fdmrms=' + fdmrms + '' + '&fdname=' + fdname + '' + '&fdemail=' + fdemail + '' + '&fdphone=' + fdphone + '' + '&fadmessage=' + fadmessage + '' + '&po=' + po + '';
        //alert(dataString); return false;


        $.ajax({
            type:"POST",
            url:"assets/php/booking-form.php",
            data:dataString,
            success:function () {
                $('.reservation-now').append("<div style=\"overflow: hidden; clear: both; \"></div><div style=\"overflow: hidden; clear: both; margin-top: 20px; \" class=\"alert alert-success fade in\"><button class=\"close\" data-dismiss=\"alert\" type=\"button\">&times;</button><strong>Email Submitted!</strong></div>");
                //$('.reservation-now')[0].reset();
            }
        });
        return false;
    });
});

Thanks for any ideas:)

  • Have you done any debugging to figure out _where_ the problem is happening? There are a number of steps to this process. Find out which step is the last step that has the value as expected, and then see what happens after that. – Patrick Q Oct 02 '19 at 19:51
  • I didnt, dont really know how to do that, can you help me with that ? – Martin Sprušanský Oct 02 '19 at 20:06
  • I can't really give you a full tutorial on basic debugging, no. Just go through your code and check the value of the related variables at various points (using `var_dump()`, `console.log()`, etc depending on which code you're in). Check your browser's network inspector to see the value sent on the request. – Patrick Q Oct 02 '19 at 20:11

1 Answers1

0

The input name on your html form is fd-phone but you are looking for $_POST['fdphone']. Wrong spelling.

Jack Albright
  • 509
  • 3
  • 11