I am trying to run a submit form in php. This is HTML from Bootstrap 3.0

I am making a contact page for a site using the Twitter Bootstrap 3.0 framework. This is HTML.

<form action="mail.php" name="contactform"  method="post" id="contact-form">
                <div class="row">
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="name"> Name</label>

                                    <input id="name" class="form-control" type="text" name="name" placeholder="Enter you name" value="" required/>

                            </div>
                            <div class="form-group">
                                 <label for="email">Email Address</label>
                                <div id="input_email" class="input-group">
                                    <span class="input-group-addon"><span class="glyphicon glyphicon-envelope"></span></span>
                                    <input id="email" class="form-control" type="email" name="email" placeholder="Enter your email" value="" required />
                                </div>
                            </div>

                            <div class="form-group">
                                <label for="subject"> Subject</label>

                                    <input id="subject" class="form-control" type="text" name="subject" placeholder="Subject"/>

                            </div>

                            </div>

                            <div class="col-md-6">
                            <div id="input_message" class="col-md-12">
                                    <textarea id="comments" class="form-control" name="message" rows="6" placeholder="Your Suggestion ..." value="" required ></textarea>
                                </div>
                            </div>
                                <!-- Submit Button -->
                                <div class="col-md-12">

                                    <input class="btn btn-skin pull-right" type="submit" value="submit" id="submit">
                                </div>

                            </div>

                            </form>    

      

This is PHP:

<!DOCTYPE html>

      

  <head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content=" Contact Form Validation.">
<meta name="author" content="Julian Vanegas">
    <title>Mailing</title>
     <!--Favicon-->
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
<link rel="icon" href="favicon.ico" type="image/x-icon">
<!-- Bridge -->
<link href="bridge-contactphp.css.css" rel="stylesheet" type="text/css">
  </head>

  <body id="page-top" data-spy="scroll" data-target=".navbar-custom">
<!-- Preloader -->
<div id="preloader">
  <div id="load"></div>
</div>

  <!--Navbar-->
<nav class="navbar navbar-custom navbar-fixed-top top-nav-collapse" role="navigation">
    <div class="container">
        <div class="navbar-header page-scroll">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-main-collapse">
                <i class="fa fa-bars"></i>
            </button>
            <a class="navbar-brand" href="#page-top">
                <img  src="img/logo-svg.svg"class="logo"></img>
            </a>
        </div>

        <!-- Collect the nav links, forms, and other content for toggling -->
        <div class="collapse navbar-collapse navbar-right navbar-main-collapse">
<ul class="nav navbar-nav">
    <li><a href="index.html">Home</a></li>
    <li><a href="about.html">About us</a></li>
    <li><a href="about.html#services">Services</a></li>
    <li class="active"><a href="contact.html">Contact</a></li>
    <li><a href="sitemap.html">Sitemap</a></li>
    <li class="dropdown">
      <a href="#" class="dropdown-toggle " data-toggle="dropdown">More<b class="caret"></b></a>
      <ul class="dropdown-menu">
        <li><a href="#">Globalnode Acad</a></li>
        <li><a href="#">Community</a></li>
        <li><a href="#"></a></li>
      </ul>
    </li>
  </ul>
        </div>
        <!-- /.navbar-collapse -->
    </div>
    <!-- /.container -->
</nav>

    <?php
        $form_htmlString = "";
        if(empty($_POST['name']) || empty($_POST['email']) || empty($_POST['subject']) || empty($_POST['message'])){
            $form_htmlString = <<<EOD
            <section id=\"intro\" class=\"intro\"><div class=\"gallery-intro\"><h2> <span class=\"text_color\"> <span>fadfasfads</span> </h2><h4></h4></div><div class=\"page-scroll\"><a href=\"#sitemap\" class=\"btn btn-circle\"><i class=\"fa fa-angle-double-down animated\"></i></a></div></section><div class=\"container\"> <div class=\"row\"> <div class=\"col-xs-12 col-sm-12 col-md-12 text-center padding-20\"><div class=\"wow bounceInUp\" data-wow-delay=\"0.2s\"> <div class=\"team boxed-grey\"> <div class=\"inner\"><h5 alt=\"Internal-link List\">  Check the information you typed in. </h5> <p class=\"subtitle\"> There is one or more mistakes. </p></div></div></div></div></div></div>
            EOD;    
        }else{
            $sendTo = "jumisingo@hotmail.es";
            $subject ="Mensaje de contacto";
            $title  = "Alguien se ha contactado con usted";
            $name = $_POST["name"];
            $email = $_POST["email"];
            $subject = $_POST["subject"];
            $comments = $_POST["message"];
            $message = "\nAlguien se ha contactado con usted:"."\nNombre: ".$name."\nEmail: ".$email."\nAsunto: ".$subject."\nComentarios: ".$comments;
            mail($sendTo, $subject, $message);      
            $form_htmlString = "<section id=\"intro\" class=\"intro\"><div class=\"gallery-intro\"><h2> <span class=\"text_color\"> <span>fadfasfads</span> </h2><h4></h4></div><div class=\"page-scroll\"><a href=\"#sitemap\" class=\"btn btn-circle\"><i class=\"fa fa-angle-double-down animated\"></i></a></div></section><div class=\"container\"> <div class=\"row\"> <div class=\"col-xs-12 col-sm-12 col-md-12 text-center padding-20\"><div class=\"wow bounceInUp\" data-wow-delay=\"0.2s\"> <div class=\"team boxed-grey\"> <div class=\"inner\"><h5 alt=\"Internal-link List\">  Check the information you typed in. </h5> <p class=\"subtitle\"> There is one or more mistakes. </p></div></div></div></div></div></div>";
            echo $form_htmlString;
        }
    ?>

    <footer id="sitemap"><div class="container"><div class="row"><div class="col-md-12 col-lg-12"><div class="wow shake" data-wow-delay="0.4s"><div class="page-scroll marginbot-30 pull-right"><a href="#intro" id="totop" class="btn btn-circle"><i class="fa fa-angle-double-up animated"></i></a></div></div><p>&copy;Copyright 2015 - Global Node Inc. All rights reserved.</p></div></div></div></footer>

  </body>

      

When I run the if, it should evaluate the data entered in the HTML via the ifs and echo the html depending on the break, but it also sends out the php part. I've looked for solutions and I've seen how heredoc works, but in this case it doesn't. Any hint?

+3


source to share


1 answer


"This is what the server is responding to." Parse error: syntax error, unexpected "pending identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) at / home 2 / ina2015 / public_html / gna / contact.php on line 76"

The error is in this block of code for your heredoc.

<?php
    $form_htmlString = "";
    if(empty($_POST['name']) || empty($_POST['email']) || empty($_POST['subject']) || empty($_POST['message'])){
        $form_htmlString = <<<EOD
        <section id=\"intro\" class=\"intro\"><div class=\"gallery-intro\"><h2> <span class=\"text_color\"> <span>fadfasfads</span> </h2><h4></h4></div><div class=\"page-scroll\"><a href=\"#sitemap\" class=\"btn btn-circle\"><i class=\"fa fa-angle-double-down animated\"></i></a></div></section><div class=\"container\"> <div class=\"row\"> <div class=\"col-xs-12 col-sm-12 col-md-12 text-center padding-20\"><div class=\"wow bounceInUp\" data-wow-delay=\"0.2s\"> <div class=\"team boxed-grey\"> <div class=\"inner\"><h5 alt=\"Internal-link List\">  Check the information you typed in. </h5> <p class=\"subtitle\"> There is one or more mistakes. </p></div></div></div></div></div></div>
        EOD;  
^^^^^^^^^^^^^^ It contains spaces. There should not be any.

      

There should be nothing before or after your closing ID.

Change it like: (no spaces before or after EOD;

)



<?php
    $form_htmlString = "";
    if(empty($_POST['name']) || empty($_POST['email']) || empty($_POST['subject']) || empty($_POST['message'])){
        $form_htmlString = <<<EOD
        <section id=\"intro\" class=\"intro\"><div class=\"gallery-intro\"><h2> <span class=\"text_color\"> <span>fadfasfads</span> </h2><h4></h4></div><div class=\"page-scroll\"><a href=\"#sitemap\" class=\"btn btn-circle\"><i class=\"fa fa-angle-double-down animated\"></i></a></div></section><div class=\"container\"> <div class=\"row\"> <div class=\"col-xs-12 col-sm-12 col-md-12 text-center padding-20\"><div class=\"wow bounceInUp\" data-wow-delay=\"0.2s\"> <div class=\"team boxed-grey\"> <div class=\"inner\"><h5 alt=\"Internal-link List\">  Check the information you typed in. </h5> <p class=\"subtitle\"> There is one or more mistakes. </p></div></div></div></div></div></div>
EOD;

      

From the manual:

It is very important to note that the line with the closing identifier must not contain any characters other than the semicolon (;). This means that the identifier cannot be indented, and there must be no spaces or tabs before or after the semicolon. It is also important to understand that the first character before the close identifier must be a newline as defined by the local operating system. This is \ n on UNIX systems, including Mac OS X. The closing delimiter must also be followed by a newline.

+2


source







All Articles