Jump to content

form problem


lena_k198

Recommended Posts

HI! I dont know much about php. here is the problem.  my form is working,the problem is that when i am pressing submit button, number "1" showing up on the top left of my screen, which moves my website on about 10px down. Does anybody know what the problem is?

Here is my form:

 

 

here is my php code:

 

<?php

            if (array_key_exists('button',$_POST)) {

            $post = $_POST;

            $name = $_POST['name'];

            $email = $_POST['email'];

            $comments = $_POST['message'];

           

            $expected = array('name', 'email', 'message');

            $required = array('name', 'email', 'message');

            $missing = array();

           

           

            foreach ($_POST as $key => $value) {

            $temp = is_array($value) ? $value : trim($value);

            if (empty($temp) && in_array($key, $required)) {

            array_push($missing, $key);

            }

            elseif (in_array($key, $expected)) {

            ${$key} = $temp;

            }

            }

           

            if (!empty($email)) {

            $checkEmail = '/^[^@]+@[^\s\r\n\'";,@%]+$/';

            if (!preg_match($checkEmail, $email)){

              array_push($missing, 'email');

              }

            }

           

            if (empty($missing)){

           

            $to = '[email protected]';//put your email here

            $subject = $name; // you can put what ever subject you want here

           

            $message = "Name: $name\n\n";

            $message .= "Comments: $comments";

           

            $message = wordwrap($message, 70);

           

            $additionalHeaders = "From: $email";

            if (!empty($email)) {

            $additionalHeaders .= "\r\nReply-To: $email";

            }

           

            $mailSent = mail($to, $subject, $message, $additionalHeaders);

           

            if (empty($missing)){

            echo $mailSent;

            }

            elseif (empty($missing)){

            $mailSent = true;

            }

           

            if ($mailsent = true){

            unset($missing);

            unset($post);

              }

              } 

            }

           

            ?>

 

 

 

 

here is my form:

 

 

<form id="form" name="form" method="post" action="">

      <table width="400" border="0" cellpadding="5" cellspacing="5" bordercolor="#990000">

        <tr>

          <td colspan="2">

          <?php

           

            if ($_POST && isset($missing) && !empty($missing)) {

            ?>

            <p class="mail"> Please complete the missing item(s) indicated.</p>

            <?php

            } 

            elseif ($_POST && $mailsent = false) {

            ?>

                <p class="mail">Sorry, there was a problem sending your message.

                Please try later. </p>

            <?php

            }

            elseif ($_POST && $mailsent = true) {

            ?>

                <br /><p class="mail"><strong>Your message has been sent. We will get back to you shortly.

                </strong></p>

            <?php } ?>

         

          </td>

 

          </tr>

        <tr>

          <td valign="top"><strong>Name:</strong></td>

          <td><label>

            <input type="text" name="name" id="name"  <?php if (isset($missing)) { echo 'value="'.htmlentities($_POST['name'], ENT_QUOTES).'"';}?>/>

            <?php if(isset($missing) && in_array('name', $missing)) { ?> <span class="mail"> :Please enter your name</span> <?php }?>

          </label></td>

        </tr>

        <tr>

 

          <td valign="top"><strong>Email:</strong></td>

          <td><label>

            <input type="text" name="email" id="email" <?php if (isset($missing)) { echo 'value="'.htmlentities($_POST['email'], ENT_QUOTES).'"';}?>/>

            <?php if(isset($missing) && in_array('email', $missing)) { ?> <span class="mail"> :Please enter your email</span> <?php }?>

          </label></td>

        </tr>

        <tr>

          <td valign="top"><strong>Message:</strong></td>

          <td><label>

              <?php if(isset($missing) && in_array('message', $missing)) { ?> <span class="mail"> Please enter your Message:</span> <?php }?>

            <textarea name="message" cols="45" rows="5" wrap="virtual" id="message">

            <?php

              if (isset($missing)) {

              echo htmlentities($_POST['message']);

              } ?>

              </textarea>

          </label></td>

        </tr>

        <tr>

          <td colspan="2" align="center" valign="top"><label>

<input type="submit" name="button" id="button" value="Send Your Message" class="submit" />

           

          </label></td>

          </tr>

 

      </table>

        </form>

 

Link to comment
https://forums.phpfreaks.com/topic/168705-form-problem/
Share on other sites

I'm noticing you are echo'ing "$mailsent" which will be either "1" or "0" true/false (Boolean).  try not echoing that.

<?php
if (array_key_exists('button',$_POST)) {
$post = $_POST;
$name = $_POST['name'];
$email = $_POST['email'];
$comments = $_POST['message'];

$expected = array('name', 'email', 'message');
$required = array('name', 'email', 'message');
$missing = array();


foreach ($_POST as $key => $value) {
	$temp = is_array($value) ? $value : trim($value);
	if (empty($temp) && in_array($key, $required)) {
		array_push($missing, $key);
	}
	elseif (in_array($key, $expected)) {
		${$key} = $temp;
	}
}

if (!empty($email)) {
	$checkEmail = '/^[^@]+@[^\s\r\n\'";,@%]+$/';
	if (!preg_match($checkEmail, $email)){
		array_push($missing, 'email');
	}
}

if (empty($missing)){

	$to = '[email protected]';//put your email here
	$subject = $name; // you can put what ever subject you want here

	$message = "Name: $name\n\n";
	$message .= "Comments: $comments";

	$message = wordwrap($message, 70);

	$additionalHeaders = "From: $email";
	if (!empty($email)) {
		$additionalHeaders .= "\r\nReply-To: $email";
	}

	$mailSent = mail($to, $subject, $message, $additionalHeaders);

	if (empty($missing)){
		echo $mailSent;
	}
	elseif (empty($missing)){
		//$mailSent = true;
	}

	if ($mailsent = true){
		unset($missing);
		unset($post);
	}
}
}

             ?>

Link to comment
https://forums.phpfreaks.com/topic/168705-form-problem/#findComment-890042
Share on other sites

I didn't fix it. as stated in another thread somewhere. My brain is mush. I commented out the wrong snippet

<?php
if (array_key_exists('button',$_POST)) {
   $post = $_POST;
   $name = $_POST['name'];
   $email = $_POST['email'];
   $comments = $_POST['message'];

   $expected = array('name', 'email', 'message');
   $required = array('name', 'email', 'message');
   $missing = array();


   foreach ($_POST as $key => $value) {
      $temp = is_array($value) ? $value : trim($value);
      if (empty($temp) && in_array($key, $required)) {
         array_push($missing, $key);
      }
      elseif (in_array($key, $expected)) {
         ${$key} = $temp;
      }
   }

   if (!empty($email)) {
      $checkEmail = '/^[^@]+@[^\s\r\n\'";,@%]+$/';
      if (!preg_match($checkEmail, $email)){
         array_push($missing, 'email');
      }
   }

   if (empty($missing)){

      $to = '[email protected]';//put your email here
      $subject = $name; // you can put what ever subject you want here

      $message = "Name: $name\n\n";
      $message .= "Comments: $comments";

      $message = wordwrap($message, 70);

      $additionalHeaders = "From: $email";
      if (!empty($email)) {
         $additionalHeaders .= "\r\nReply-To: $email";
      }

      $mailSent = mail($to, $subject, $message, $additionalHeaders);

      if (empty($missing)){
         //echo $mailSent;
      }
      elseif (empty($missing)){
         $mailSent = true;
      }

      if ($mailsent = true){
         unset($missing);
         unset($post);
      }
   }
}

             ?>

Link to comment
https://forums.phpfreaks.com/topic/168705-form-problem/#findComment-890077
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.