I've written a little code that allows me to send a specific link in an automated response email based on a form submission. In other words, I have a contact form wich will be filled out by users and depending on the number of guests they put in the field, they'll receive one link or another. What I got so far is working fine but I want to create a rule in case they enter zero as value in the input field. What I want is that when they put zero, the code can tell them that 0 guests is not a valid number. Hope i'm being clear and thanks for your help in advance.
<?php
// This value will be grabbed from a form.
$guests = 21; // Enter some numeric value here.
// This is the Brochure's URL in 3 different options, depending on the Nº of guests.
$brochure = array ( '0' => 'http://www.yahoo.com', '1' => 'http://www.google.co.uk', '2' => 'http://www.kazzabe.com' );
// Start asking number of guests.
if ( $guests <= 10 ) {
// Between 1 and 10.
$brochure_link = $brochure[0];
} else if ( $guests >= 11 && $guests <= 20 ) {
// Between 11 and 20.
$brochure_link = $brochure[1];
} else ( $guests >= 21 ) {
// More than 20.
$brochure_link = $brochure[2]
};
echo 'As there will be <b>'.$guests.'</b> guests at your wedding, we proceed to send you the brochure you have requested. In order to download it, please follow this <a href="'.$brochure_link.'" target="_blank">link.</a>';
Aucun commentaire:
Enregistrer un commentaire