G
G
Ghena_292018-03-28 22:19:44
PHP
Ghena_29, 2018-03-28 22:19:44

How to make an application form with optional fields?

for example, there is a feedback form on the landing page, there are 5 fields, 2 fields are required, but how to make the remaining 3 optional, only 2 fields are filled, then send them to the mail, if 3 then only 3, and so on.
here is the handler:

<?php 
if (!empty($_POST['name']) AND !empty($_POST['phone']) AND !empty($_POST['email']) AND !empty($_POST['quantity']) AND !empty($_POST['address'])) {
         
    $theme = "New message from the site";             
             
    $letter = "This message:";
    $letter .="\n\n";
    $letter .="\nName: ".$_POST['name'];
    $letter .="\nPhone: ".$_POST['phone'];
    $letter .="\nE-mail: ".$_POST['email'];
    $letter .="\nQuantity: ".$_POST['quantity'];
    $letter .="\nAddress: ".$_POST['address'];
    
    if (mail("[email protected]", $theme, $letter)){
      header("Location: thanks.html");
    } else {
      header("Location: error.html");
    }  
              
} else {
  header("Location: error.html");
}

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sergey, 2018-03-28
@gangstarcj

You need to know at least a little about php

U
Uncle Vanya, 2018-03-29
@QSem

I don't understand php. But there seems to be threads for this.
https://ru.stackoverflow.com/questions/605555/Vali...

G
Ghena_29, 2018-03-29
@Ghena_29

Thanks for the reply but I already did it myself
in the condition I wrote the fields that are required and must be filled in, and deleted which at will ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question