Announcement

Collapse
No announcement yet.

PHP If statement on forms tutorial

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • PHP If statement on forms tutorial

    The code below is part of my adapted action.php from the forms tutorial
    My form has a multiselect listbox hence the @implode. I do not want the submit or Comments field emailed to me (basically because if there is a comment $mailto gets changed to my support address) The names are correct on the form but I still get the comments so I guess the if statement is wrong. New to PHP so greatful for any help!


    $mailto = "feedback@no925.info";
    while (list ($key, $val) = each ($HTTP_POST_VARS)) {
    if ($key != "submit" && $key != "Comments") {
    if (is_array($val)) {
    @$val = @implode(", ",$val);
    }

    $mailbody .= "$key: $val\n";
    }
    }

    mail($mailto, $mailsubj, $mailbody, $mailhead);

    Regards
    Richard

  • #2
    Re: PHP If statement on forms tutorial

    Your code is correct. Are you sure the field is named "Comments" ?

    Also, can you please explain what you mean by (basically because if there is a comment $mailto gets changed to my support address) ?
    Navaldesign
    Logger Lite: Low Cost, Customizable, multifeatured Login script
    Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
    DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
    Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

    Comment


    • #3
      (basically because if there is a comment $mailto gets changed to my support address)

      Many thanks for checking code.

      I have named the field again and republished with no changes so it remains a mystery.

      I set up two email adresses support@ with a "message received" autoresponder for question type emails and feedback@ to receive the feedback form.

      Outllook plays different sounds on their arrival so I can give immediate response to questions.

      My site offers product information and the feedback form asks if the info is useful and which of the recommended products they will use (hence multiselect listbox). The form also includes a textbox for comments or questions.

      I always want the form to be sent to feedback@ but I do not require the comments. If comments are made then these need to be sent to support@ as well for immediate attention.

      Hope that explains things better.

      Regards
      Richard

      Comment


      • #4
        Re: PHP If statement on forms tutorial

        However, i still do not understand: you have two forms? and you have two processing scripts?
        If you have only one processing script, the email will be always sent to the email coded in the script. So it would be enough to have two different forms, one with comments field and one without. In each of the forms, add a hidden field with your email (hidden field name: myemail, hidden field value: feedback@no925.info for the first form, support@no925.info for the second form.

        Modify the script as follows:

        @$mailto = addslashes($_POST['myemail']);
        while (list ($key, $val) = each ($HTTP_POST_VARS)) {
        if ($key != "submit") {
        if (is_array($val)) {
        @$val = @implode(", ",$val);
        }

        $mailbody .= "$key: $val\n";
        }
        }

        mail($mailto, $mailsubj, $mailbody, $mailhead);

        If this is a unique form, so you cannot avoid the comments field, you need to make your email address selectable by the visitor (using a listbox with the departments as items, and the relevant email addresses as values). In that case you will not add a hidden field, but a "Department to contact" listbox, named f.e. "department" and just use a double "if" statement:

        @$mailto = addslashes($_POST['department']);
        while (list ($key, $val) = each ($HTTP_POST_VARS)) {
        if ($key != "submit") {
        if ($key != "Comments) {

        if (is_array($val)) {
        @$val = @implode(", ",$val);
        }

        $mailbody .= "$key: $val\n";
        }
        }
        }

        Posting here the URLs of the form (or forms), as well as explaining if you only have one or two different action scripts, would help a lot in helping you.
        Navaldesign
        Logger Lite: Low Cost, Customizable, multifeatured Login script
        Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
        DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
        Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

        Comment


        • #5
          Re: PHP If statement on forms tutorial

          Nope!!

          I have indented for readability does PHP not like this?

          I've included the whole code (I suppose if nothing else I'll just accept the comments in feedback@)



          <?PHP # Feedback Form Emailer
          $email = $HTTP_POST_VARS[Email];
          $comments=$HTTP_POST_VARS[Comments];
          $mailsubj = "Feedback Form Response";
          $mailhead = "From: $email\n";
          reset ($HTTP_POST_VARS);
          $mailbody = "925 - Feedback form values:\n\n";

          if ($comments !="Your comments or questions." && !empty($email)) {
          $mailto = "support@no925.info";

          while (list ($key, $val) = each ($HTTP_POST_VARS)) {
          if ($key != "submit") {
          if (is_array($val)) {
          @$val = @implode(", ",$val);
          }

          $mailbody .= "$key: $val\n";
          }
          }
          mail($mailto, $mailsubj, $mailbody, $mailhead);
          }


          $mailto = "feedback@no925.info";
          while (list ($key, $val) = each ($HTTP_POST_VARS)) {
          if ($key != "submit") {
          if ($key != "Comments") {
          if (is_array($val)) {
          @$val = @implode(", ",$val);
          }

          $mailbody .= "$key: $val\n";
          }
          }
          }

          mail($mailto, $mailsubj, $mailbody, $mailhead);
          ?>

          Regards
          Richard

          Comment


          • #6
            Re: PHP If statement on forms tutorial

            This script will send the email to both email addresses, or a double email to the same address. And what is the "&& !empty($email))" for ?
            Navaldesign
            Logger Lite: Low Cost, Customizable, multifeatured Login script
            Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
            DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
            Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

            Comment


            • #7
              Re: PHP If statement on forms tutorial

              Sorry I obviously didn't view all of your last but one message.

              No There is one form and one script. The scrpit is in the body section of a page I created which says thanks for feedback and has links to home page. (As per tutorials)

              I notice that all leading spaces are removed in forum so you couldn't see indentation.

              All bar the exclusion of the Comments data the script works. It sends one email unless there are comments and a return email address. Then it will send one email to each address. At the moment they are identical and thats the point, the one to feedback@ should not have comments.


              The && !empty($email)) checks that the sender has included their email address on the form in the box named Email. If they have not then I can not repond as they are anonymous (field is optional) and the form just gets sent to my feedback address.

              Regards
              Richard

              Comment


              • #8
                Re: PHP If statement on forms tutorial

                Try this one:

                <?PHP
                // Feedback Form Emailer

                @$email = addslashes($HTTP_POST_VARS[email]);
                @$comments= addslashes($HTTP_POST_VARS[Comments]);
                $mailsubj = "Feedback Form Response";
                $mailhead = "From: $email\n";
                reset ($HTTP_POST_VARS);
                $mailbody = "925 - Feedback form values:\n";
                if ($comments == "Your comments or questions." and ($email !="")){
                while (list ($key, $val) = each ($HTTP_POST_VARS)) {
                if ($key != "submit") {
                if (is_array($val)) {
                @$val = @implode(", ",$val);
                }
                $mailbody .= "$key: $val\n";
                }
                }
                $mailto = "support@no925.info";
                mail($mailto, $mailsubj, $mailbody, $mailhead);
                $mailto = "feedback@no925.info";
                mail($mailto, $mailsubj, $mailbody, $mailhead);
                }
                else
                {
                $mailto = "feedback@no925.info";
                while (list ($key, $val) = each ($HTTP_POST_VARS)) {
                if ($key != "submit") {
                if ($key != "Comments") {
                if (is_array($val)) {
                @$val = @implode(", ",$val);
                }
                $mailbody .= "$key: $val\n";
                }
                }
                }
                mail($mailto, $mailsubj, $mailbody, $mailhead);
                }
                ?>


                Sometimes elementary logical schemes are faster to code, even though they require some more lines.
                This one will send an email to both addresses, ONLY if the Comments is different from "Your comments or questions." and the email field is filled in.

                In ALL other cases, it will send to the support address only. Or maybe i have misread your post ?
                Navaldesign
                Logger Lite: Low Cost, Customizable, multifeatured Login script
                Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
                DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
                Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

                Comment


                • #9
                  Re: PHP If statement on forms tutorial

                  Quick Reply:

                  Wow thanks for the recode It's very generous to spend the time.
                  I have tried it and it is not quite there in relation to the locations but the comments separtation works!! - Reworked it yesterday and then didn't save the changes or they vanished. Will take another look today.

                  Many Thanks

                  Regards
                  Richard

                  Comment


                  • #10
                    Re: PHP If statement on forms tutorial

                    HOORAY

                    Sometimes you wonder if what you are doing is really worth it!!!!

                    It was simple but being used to VBA I kept missing it.
                    If ($comments = "Your comments or questions." and ($email !="")){
                    should be
                    if ($comments == "Your comments or questions." and ($email !="")){

                    Well thanks for your help.

                    Now just to validate that Email is present if the newsletter checkbox is true.
                    Oh well fingers crossed.

                    Regards
                    Richard

                    Comment

                    Working...
                    X