Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Getting 404 Undefined Error while submitting form

I'm getting

Error 404 Undefined

"Not Found The requested URL /signup/undefined was not found on this server."

I created an .htaccess and deleted the file after this error. All my forms get this error after clicking send. I'm not sure what to do.

Please help :)

I attached my code (The first piece of code is under /signup/index.php. The second piece of code is under /signup/success/index.php)

<?php
  $pageTitle = "Agendar Reunión";
  require_once("../php/config.php");
  include(ROOT_PATH . "php/header.php");
?>
      <div class="signup" style="margin-top: -65px;">
        <div class="container text-center sign">
          <div class="col-lg-12">
            <h1 style="font-size: 36px; font-weight: 300;">Agenda una reunión con nosotros.</h1>
            <p style="font-size: 20px; font-weight: 100;">Descubre como WSNPro puede ayudar a tu empresa a crear
              tus nuevos productos y servicios innovadores y exitosos.</p>
            <div class="row">
              <div class="col-md-6 col-md-offset-3">
                <form class="form-horizontal" role="form" name="formSignup" method="POST" action="<?php echo BASE_URL; ?>success/" id="formSignup">
                  <hr>
                  <fieldset>
                    <!-- Text input-->
                    <div class="form-group">
                      <div class="col-md-8 col-md-offset-2">
                        <label class="control-label pull-left" for="nombre" style="font-size: 18px;">Nombre *</label>
                        <input type="text" class="form-control input-md" id="nombre" name="nombre" required>
                      </div>
                    </div>
                    <!-- Text input-->
                    <div class="form-group">
                      <div class="col-md-8 col-md-offset-2">
                        <label class="control-label pull-left" for="apellido" style="font-size: 18px;">Apellido *</label>
                        <input type="text" class="form-control input-md" id="apellido" name="apellido" required>
                      </div>
                    </div>
                    <!-- Text input-->
                    <div class="form-group">
                      <div class="col-md-8 col-md-offset-2">
                        <label class="control-label pull-left" for="email" style="font-size: 18px;">Email *</label>
                        <input type="text" class="form-control input-md" id="email" name="email" required>
                      </div>
                    </div>
                    <!-- Text input-->
                    <div class="form-group">
                      <div class="col-md-8 col-md-offset-2">
                        <label class="control-label pull-left" for="empresa" style="font-size: 18px;">Empresa *</label>
                        <input type="text" class="form-control input-md" id="empresa" name="empresa" required>
                      </div>
                    </div>
                    <!-- Text input-->
                    <div class="form-group">
                      <div class="col-md-8 col-md-offset-2">
                        <label class="control-label pull-left" for="cargo" style="font-size: 18px;">Cargo *</label>
                        <input type="text" class="form-control input-md" id="cargo" name="cargo" required>
                      </div>
                    </div>
                    <!-- Text input-->
                    <div class="form-group">
                      <div class="col-md-8 col-md-offset-2">
                        <label class="control-label pull-left" for="telefono" style="font-size: 18px;">Teléfono *</label>
                        <input type="tel" class="form-control input-md" id="telefono" name="telefono" required>
                      </div>
                    </div>
                    <!-- Text input-->
                    <div class="form-group">
                      <div class="col-md-8 col-md-offset-2">
                        <label class="control-label pull-left" for="select_empresa" style="font-size: 18px;">Tamaño de tu Empresa *</label>
                        <select class="input-lg" id="select_empresa" name="select_empresa" style="width: 100%;" required>
                          <option value="0 - 10 personas">0 - 10 personas</option>
                          <option value="11 - 100 personas">11 - 100 personas</option>
                          <option value="101 - 500 personas">101 - 500 personas</option>
                          <option value="501 - 1000 personas">501 - 1000 personas</option>
                          <option value="+1000 personas">+1000 personas</option>
                        </select>
                      </div>
                    </div>
                    <input type="hidden" class="form-control input-md" id="signup_page" name="signup_page" value="Signup">
                    <hr>
                    <!-- Signup Buttons -->
                    <div class="form-group">
                      <div class="col-md-8 col-md-offset-2">
                        <button type="submit" id="signup" class="btn btn-lg btn-info btn-embossed btn-block">Agendar Reunión</button>
                      </div>
                    </div>
                  </fieldset>
                </form>
              </div><!-- /.col-lg-12 -->
            </div><!-- /.row -->
          </div>
        </div>
      </div>
      <script>
        $(document).ready(function() {
          $('#formSignup').bootstrapValidator({
            fields: {
              nombre: {
                validators: {
                  notEmpty: {
                    message: 'Debe escribir su nombre.'
                  }
                }
              },
              apellido: {
                validators: {
                  notEmpty: {
                    message: 'Debe escribir su apellido.'
                  }
                }
              },
              email: {
                validators: {
                  notEmpty: {
                    message: 'Debe escribir su email.'
                  },
                  emailAddress: {
                    message: 'Debe escribir un email válido.'
                  }
                }
              },
              empresa: {
                validators: {
                  notEmpty: {
                    message: 'Debe escribir una empresa.'
                  }
                }
              },
              cargo: {
                validators: {
                  notEmpty: {
                    message: 'Debe escribir un cargo.'
                  }
                }
              },
              telefono: {
                validators: {
                  notEmpty: {
                    message: 'Debe escribir un teléfono.'
                  }
                }
              }
            }
          });
        });
      </script>
<?php
  include(ROOT_PATH . "page/steps.php");
  include(ROOT_PATH . "php/footer.php");
?>
<?php
  header("Content-Type: text/html; charset=UTF-8");

  if ($_SERVER["REQUEST_METHOD"] == "POST")
  {
    $subject = "Contacto WSNPro" . " de " . $_POST["nombre"] . " " . $_POST['apellido'];
    $message .= "Nombre: " . $_POST["nombre"] . "\n";
    $message .= "Apellido: " . $_POST["apellido"] . "\n";
    $message .= "Email: " . $_POST["email"] . "\n";
    $message .= "Empresa: " . $_POST["empresa"] . "\n";
    $message .= "Cargo: " . $_POST["cargo"] . "\n";
    $message .= "Teléfono: " . $_POST["telefono"] . "\n";
    $message .= "Tamaño de Empresa: " . $_POST["select_empresa"] . "\n";
    $message .= "Página de Origen: " . $_POST["signup_page"] . "\n";
    $header = "From: " . $_POST["email"] . "\r\n";
    $header.= "MIME-Version: 1.0\r\n";
    $header.= "Content-Type: text/plain; charset=utf-8\r\n";
    $header.= "X-Priority: 1\r\n";

    //mail('name@email.com', $subject, $message, $header);
  }
?>
<?php
  $pageTitle = "Gracias!";
  require_once("../../php/config.php");
  include(ROOT_PATH . "php/header.php");
?>
      <script>mixpanel.track("Página Success Formulario Reunión Enviado");</script>
      <div class="signup" style="margin-top: -65px;">
        <div class="container text-center sign">
          <div class="col-lg-12">
            <h1 style="font-size: 36px; font-weight: 300;">Agenda una reunión con nosotros.</h1>
            <p style="font-size: 20px; font-weight: 100;">Descubre como WSNPro puede ayudar a tu empresa a crear
              tus nuevos productos y servicios innovadores y exitosos.</p>
            <div class="row">
              <div class="col-md-12" style="padding: 120px;">
                <h1 style="font-size: 24px; font-weight: 200;">Muchas gracias, dentro de las próximas 2 horas nos pondrémos en contacto contigo.</h1>
              </div><!-- /.col-lg-12 -->
            </div><!-- /.row -->
          </div>
        </div>
      </div>
<?php include(ROOT_PATH . "php/footer.php"); ?>

3 Answers

Ok, I got it sorted out. It was my fault by setting mixpanel's link tracker onto a button inside the forms.

Thanks for all the help!

What URL are you submitting the form to? I see that you are using the constant -> BASE_URL but I don't see that constant is defined in the code that you provided. That could be why you are getting an undefined error.

action="<?php echo BASE_URL; ?>success/"

Hi, Amit! You've said form started giving you 404 after you had created .htaccess file. Try resetting browser cache — they like saving 301 redirects and continuing redirecting you, even you've deleted .htaccess from a web server.