Jump to content

Patwan

Members
  • Posts

    34
  • Joined

  • Last visited

Posts posted by Patwan

  1.  

    I've looked around for a few examples and followed the tutorials here but a lot of them are either too advanced for my grasp of PHP as abeginner or their examples are too specific to their own projects. Here's my new snippet

    
    

    // Check Checkbox

    if(!empty($_POST["checkbox"])){

    $checkbox = $_POST['checkbox'];

    foreach ($_POST["checkbox"] as $value) //loop to store and display values of individual checkboxes

    {echo "$value";

    }

    else{$checkbox= test_input($_POST["$value"]);}}

     

     

  2. // Check Checkbox
    	if(!empty($_POST["checkbox"])){
                 
    			 
    			 $checkbox = array("HP", "DELL", "ACER", "TOSHIBA"); 
    			 
    			 foreach ($checkbox as $value) {
                     echo "$checkbox";
    			 }
                else {
    		$checkbox = test_input($_POST["checkbox"]);}
    }
    

    Followed the tutorial. But still can't get it post the values in my inbox..

  3. <?php
    if ($_SERVER["REQUEST_METHOD"] == "POST") {
    
    // Check Checkbox
    	if(!empty($_POST["checkbox"])){
                 $value=false;
    			 
                foreach($_POST["checkbox"] as $selected)
    	 foreach ["HP", "DELL", "ACER", "TOSHIBA"];
                $checkboxErr = "Please Select one of these options";
              } else {
    		$checkbox = test_input($_POST["checkbox"]);}
    }
    ?>
    

    How about that? Am not sure of it,,Could you explain using an example so as to follow easily

  4. This way

    <?php
    if ($_SERVER["REQUEST_METHOD"] == "POST") {
    
    // Check Checkbox
    	if(!empty($_POST["checkbox"])){
                 $value=false;
    			 
                foreach($_POST["checkbox"])
    			
                $checkboxErr = "Please Select one of these options";
              } else {
    		$checkbox = test_input($_POST["checkbox"]);}
    		
    		$array = ["HP", "DELL", "ACER", "TOSHIBA"];
    }
    ?>
    
  5. Hello dsonesuk, was trying to code a multiple checkbox array for the form above. Cant figure out the problem in the code below? Kindly assist..

     

    HTML code

    Which type of laptop would you like us to deliver to you? <span class= "error"> * </span>
    
     <br> <br> <input type="checkbox" class="input" name="checkbox[]" value="HP"> H.P <br>
                    <input type="checkbox" class="input" name="checkbox[]" value="DELL" > DELL <br>
                    <input type="checkbox" class="input" name="checkbox[]" value="ACER" > ACER<br>
                    <input type="checkbox" class="input" name="checkbox[]" value="TOSHIBA" > TOSHIBA
    
    

    PHP code

    <?php
    if ($_SERVER["REQUEST_METHOD"] == "POST") {
    
    // Check Checkbox
    	if(!empty($_POST["checkbox"])){        
    
                $checkboxErr = "Please Select one of these options";
              } else {
    		$checkbox = test_input($_POST["checkbox"]);}
    		
    		$array = ["HP", "DELL", "ACER", "TOSHIBA"];
    }
    ?>
    
  6. Hi all,
    I have a HTML contact form on my website whereby when the user hits submit button I get all other inputs in my email except option from Drop-down list. What could be the problem?

    ~ Kindly assist

    <?php
    //initialize variables and set to empty values
    $name = $phone = $email = $business = $industry= "";
    $nameErr = $phoneErr = $emailErr = $businessErr = $industryErr="";
    
    ini_set('display_errors', 1);
    error_reporting(E_ALL);
    
    if ($_SERVER["REQUEST_METHOD"] == "POST") {
    
        $valid = true;
    
        //check if name contains letters and white-space
        if (empty($_POST["name"])) {
    
            $valid = false;
    
            $nameErr = "Please fill out this field";
            echo 'name is empty<br>';
        } else {
            $name = test_input($_POST["name"]);
            if (!preg_match("/^[a-zA-Z ,.-]*$/", $name)) {
    
                $valid = false;
    
                $nameErr = "*Only Letters and white-spaces are allowed*";
            } /* else {
              echo'name is valid<br>';
              } */
        }
    
        //check if phone contains numbers
        if (empty($_POST["phone"])) {
    
            $valid = false;
    
            $phoneErr = "Please fill out this field";
            echo'phone is empty<br>';
        } else {
            $phone = test_input($_POST["phone"]);
            if (!preg_match("/^[0-9 ,+.-]*$/", $phone)) {
    
                $valid = false;
    
                $phoneErr = "*Only numbers are allowed*";
            
            }
    
            /*   else {
              echo'  phone is valid<br>';
              } */
        }
    
        //check if email is valid
        if (empty($_POST["email"])) {
    
            $valid = false;
    
            $emailErr = "Please fill out this field";
            echo'email is empty<br>';
        } else {
            $email = test_input($_POST["email"]);
            if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
    
                $valid = false;
    
                $emailErr = "*Invalid email address*";
               
            }
    
            /*  else {
              echo'email is valid<br>';
              }
             */
        }
    	
    	      //check if industry is filled
    	 if (empty($_POST["industry"])) {
    		 $industryErr = "Please Select an item";
    	} else 
    	{$industry = test_input($_POST["industry"]);}
    	
    	
    }
    ?>
    
    <!DOCTYPE html>
    <html>
        <head>
            <meta name= "robots" content= "noindex, nofollow">
            <meta charset="UTF-8">
            <meta name= "author" content= "Kelly James">
            <link href= "style.css" rel= "stylesheet" type= "text/css">
            <title> Contact form </title>
        </head>
    
        <body>
    
            <img src= "images/logo.gif" border= "0" width= "240" height="160">
    
            <br>
            <div class="form">
    
                <form method= "post" action= "<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" >
    
                    <h4 id="h4form"> Please fill the form below to kick start your project. <br> <br> <font color="red"> *required field </font> </h4>
    
                    <br> What is your name? <input type= "text" class= "input" name= "name"  placeholder= "e.g Nelson Mandela" value="<?php echo $name; ?>"  required> <span class= "error"> * <br> <?php echo $nameErr; ?> </span>
    
                    <br> <br>What is your phone number? <input type= "text" class= "input" name= "phone"  value="<?php echo $phone; ?>" placeholder= "e.g 0722222222" required> <span class= "error"> * <br> <?php echo $phoneErr; ?> </span>
    
                    <br> <br> What is your email address? <input type= "email" class= "input" name= "email" placeholder= "will not be published" value="<?php echo $email; ?>" required> <span class= "error"> * <br> <?php echo $emailErr; ?> </span>
    				
    				<br> <br> What industry is your business? <span class= "error"> * <?php echo $industryErr;?> </span>
                        <select class= "input" name="industry" required>
                         <option value= "" > Select  Industry </option>
                         <option value= "Air_and_Travel" >Air & Travel </option>
                         <option value= "Agriculture">Agriculture</option> 
    					 <option value= "Architecture and Structural"> Architecture and Structural </option> 
    					 <option value="Attorney & legal"> Attorney & Legal </option> 
    					 <option value="Automotive"> Automotive </option>
                         <option value= "Consultation"> Consultation </option>
    					 </select> 
    					 
    				<br> <br> <button class="submit" type= "submit" value= "Submit"> Submit  Form </button>
    
    
    
                </form>
            </div>
        </body>
    </html>
    
  7. Hey folks, I took heed of your advice & have tried rectifying the form over the weekend. I noticed that PHPMailer works fine but after adding $valid functions it ceases from sending emails to my inbox.

    - I still think there is an error in how I code the $valid functions to enhance validation before sending mail via PHPMailer.

    -Could any moderator in this forum create a tutorial of "Validating a PHP contact form using Regexp before sending via PHPMailer" so that me & others in my position could benefit.

    ~ Kindest regards...

  8. Yeah, I tested the PHPMailer before, it worked fine, by then it could send emails before passing user input through validation. But after I added the $valid functions in the coding to help in checking validation before sending any mail, it stopped sending mails to my inbox. I don't know what went wrong after adding $valid functions to the code?

  9. After configuration of the code above, I restarted my XAMPP server but the problem still persists. Could there be any other file I need to configure, cause its` driving me nuts & am running out of time

     

    ~ Any advice will be highly appreciated?

  10. Hey, I have configured C:\xampp\php\php.ini and C:\xampp\sendmail\sendmail.ini files in XAMPP server.

    In C:\xampp\php\php.ini file, I found extension=php_openssl.dll and removed the semicolon from the beginninng of the line.

    I also changed the following bold lines in [mail function]:



    [mail function]
    ; For Win32 only.
    ; http://php.net/smtp
    SMTP=smtp.gmail.com
    ; http://php.net/smtp-port
    smtp_port=587

    ; For Win32 only.
    ; http://php.net/sendmail-from
    sendmail_from =my-gmail-id@gmail.com

    ; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
    ; http://php.net/sendmail-path
    sendmail_path ="\"C:\xampp\sendmail\sendmail.exe\" -t"

    I then opened C:\xampp\sendmail\sendmail.ini and changed the following lines writen in bold

     

    [sendmail]

    ; you must change mail.mydomain.com to your smtp server,
    ; or to IIS's "pickup" directory. (generally C:\Inetpub\mailroot\Pickup)
    ; emails delivered via IIS's pickup directory cause sendmail to
    ; run quicker, but you won't get error messages back to the calling
    ; application.

    smtp_server=smtp.gmail.com

    ; smtp port (normally 25)

    smtp_port=587

    ; SMTPS (SSL) support
    ; auto = use SSL for port 465, otherwise try to use TLS
    ; ssl = alway use SSL
    ; tls = always use TLS
    ; none = never try to use SSL

    smtp_ssl=auto

    ; the default domain for this server will be read from the registry
    ; this will be appended to email addresses when one isn't provided
    ; if you want to override the value in the registry, uncomment and modify

    ;default_domain=mydomain.com

    ; log smtp errors to error.log (defaults to same directory as sendmail.exe)
    ; uncomment to enable logging

    error_logfile=error.log

    ; create debug log as debug.log (defaults to same directory as sendmail.exe)
    ; uncomment to enable debugging

    ;debug_logfile=debug.log

    ; if your smtp server requires authentication, modify the following two lines

    auth_username=my-gmail-id@gmail.com
    auth_password=**************

×
×
  • Create New...