Main
 New Members

 E-mail
 FTP
 SSH
 SSL
 Herr. of Design

 To ask for aid

 

Processing a form with PHP.
Part 3: The last details.
By: Falcon

I am going to loosen a small segment to them of code. they are not scared!

if ($elnombre == "" || $elemail == "" || $elmensaje == "") \ {
print “Is necessary to fill all the fields! ?;
} else \ {
print “Thank you very much to contact to us! ?;
}

That it does the previous thing? Basically it verifies that all the fields in the form have been filled. If it is not thus shows the message: “It is necessary to fill all the fields? and if everything were well it shows the message: “Thank you very much to contact to us?.

But we are going to detach it.

if/else

if and else (si/de another way) are two of the tools of useful construction of code but in any programming language. Basically it is a game that conditions an action to other elaborated previously. We do not lose ourselves in semantics and we go to the examples:

The breast commanded to pepito to the market and it told him: - If there are white eggs you bring a dozen to me if you do not bring red egg average to me twelfth

In the previous phrase we see a conditioner: “If there are white eggs? followed of an order in case the conditioner is successful: “you bring a dozen to me? soon is defined that there is an alternative in case the conditioner is not successful: “if not? soon the order in this case: “you bring red egg average to me twelfth?

if ($elnombre == "" || $elemail == "" || $elmensaje == "")
This is conditions it to you. In colloquial language this leeria thus:
If the variable $elnombre this empty one or if barible $elemail this empty one or if the variable $elmensaje this empty one.

In PHP the symbols || they mean: or or in Spanish: or
There will be one who already it noticed that after each variable there are two signs of equal (=) instead of one. This is very important since we are not assigning values to the variables, but we are comparing the value of the variable to another value that in this case is empty and that "" is defined with two followed quotation marks. If we only left to a sign of equal (=) PHP asignaria him the value "" to the variable, that is to say, dejaria empty. For example:

$elnombre = "";

Advancing in the code segment we see a symbol “\ {? This symbol means that the order begins to execute in case the conditioner has been successful, another symbol the same only that inverse “}? indicates to PHP that this order has finished.

Between these two symbols we see the action:

print “Is necessary to fill all the fields! ?;

This says to him to PHP that there is to show a message that says: It is necessary to fill all the fields! The function print does that indeed, writes in the document HTML that is sent to him to the visitor which is indicated between the quotation marks.

Soon it is indicated that there is an alternative: else
If it were arrived up to here is that the conditioner I am not successful, that is to say, the visitor if full all the fields, then we defined as action:

print “Thank you very much to contact to us! ?;

We are going to see as all the script complete is seen:

<? php
$elnombre = $_POST [‘name’];
$elemail = $_POST [‘email’];
$elmensaje = $_POST [‘message’];

$elasunto = “finishes to Me contacting in my website! ?;

$adondeva = “falcon@escorts-webhosting.com?;

$encabezados. = “From: $elemail<$elemail> \ n?;
$encabezados. = “X-Sender: <$elemail> \ n?;
$encabezados. = “X-Mailer: PHP \ n?;
$encabezados. = “Return-Path: <$elemail> \ n?;

$mensaje. = “Here this what arrived: \ n \ n?;
$mensaje. = “$elnombre with the direction: $elemail \ n?;
$mensaje. = “It wrote: \ n$elmensaje \ n?;

if ($elnombre == "" || $elemail == "" || $elmensaje == "") \ {
print “Is necessary to fill all the fields! ?;
} else \ {
print “Thank you very much to contact to us! ?;
mail ($adondeva, $elasunto, $mensaje, $encabezados);
}

>

Those that estan kind will have fixed that we placed the function mail () within the actions in case the conditioner has not been successful. Is this because we want to only receive the mail when the visitor has filled all the fields, or no?

There are many things that can be done! , for example, if it is wanted to send the message to mail two-way traffic different:

We define another mail to where to send the mail:

$otrocorreo = “luis@escorts-webhosting.com?;

And soon only we mentioned another function of mail:

mail ($otrocorreo, $elasunto, $mensaje, $encabezados);

And script quedaria thus:

<? php
$elnombre = $_POST [‘name’];
$elemail = $_POST [‘email’];
$elmensaje = $_POST [‘message’];

$elasunto = “finishes to Me contacting in my website! ?;

$adondeva = “falcon@escorts-webhosting.com?;
$otrocorreo = “luis@escorts-webhosting.com?;

$encabezados. = “From: $elemail<$elemail> \ n?;
$encabezados. = “X-Sender: <$elemail> \ n?;
$encabezados. = “X-Mailer: PHP \ n?;
$encabezados. = “Return-Path: <$elemail> \ n?;

$mensaje. = “Here this what arrived: \ n \ n?;
$mensaje. = “$elnombre with the direction: $elemail \ n?;
$mensaje. = “It wrote: \ n$elmensaje \ n?;

if ($elnombre == "" || $elemail == "" || $elmensaje == "") \ {
print “Is necessary to fill all the fields! ?;
} else \ {
print “Thank you very much to contact to us! ?;
mail ($adondeva, $elasunto, $mensaje, $encabezados);
mail ($otrocorreo, $elasunto, $mensaje, $encabezados);
}

>

Tooodo is friendly!

<-- Part 2: We begin to program!
<-- Part 1

   

Web Hosting | Packages | Frequent questions | Contact to us | Terms and Conditions | It orders Now