FormToEmail list/menu true/false

Hello…

My problem is that I have created the form and formtoemail.php and everything works fine and now I created a list to choose the product…
Here is the list:
[php]

Molimo odaberite Trup #T100 Trup #T101 Trup #T102 Trup #T103 Trup #T104 Trup #T105 Trup #T106 Trup #T107 Trup #T108 Trup #T109 Trup #T110 Trup #T111 Trup #T112 Trup #T113 Trup #T114 [/php]

And the current FormToEmail.php code

[php]

<?php if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "info@clm-pro-tk";
$email_subject = "Your email subject line";
 
 
function died($error) {
    // your error code can go here
    echo "Ispri&#269;avano se, prilikom po?iljanja va?eg upita smo prona?li pogre?ku/e. ";
    echo "Pogre?ka/e &#263;e biti prikazane ispod.<br /><br />";
    echo $error."<br /><br />";
    echo "Vrni se i popravi.<br /><br />";
    die();
}
 
// validation expected data exists
if(!isset($_POST['ime']) ||
    !isset($_POST['email']) ||
    !isset($_POST['naslov']) ||
    !isset($_POST['poruka'])) {
    died('Ispri&#269;avamo se, prona?li smo npogre?ku prilikom slanja va?eg upita.');      
}
 
$ime = $_POST['ime']; // required
$email = $_POST['email']; // required
$naslov = $_POST['naslov']; // required
$poruka = $_POST['poruka']; // required

$trup = $_POST[‘select’] ; // not required
$newsletter = $_POST[‘newsletter’]; // not required

$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';

if(!preg_match($email_exp,$email)) {
$error_message .= ‘E-mail ne valja.
’;
}
$string_exp = “/^[A-Za-z .’-]+$/”;
if(!preg_match($string_exp,$ime)) {
$error_message .= ‘Ime ne valja.
’;

}
if(strlen($naslov) < 2) {
$error_message .= ‘Naslov ne valja.
’;

}
if(strlen($poruka) < 2) {
$error_message .= ‘Poruka ne valja.
’;
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = “Form details below.\n\n”;

function clean_string($string) {
  $bad = array("content-type","bcc:","to:","cc:","href");
  return str_replace($bad,"",$string);
}
 
$email_message .= "Ime: ".clean_string($ime)."\n";
$email_message .= "Email: ".clean_string($email)."\n";
$email_message .= "Naslov: ".clean_string($naslov)."\n";
$email_message .= "Poruka: ".clean_string($poruka)."\n";

// create email headers
$headers = 'From: '.$email."\r\n".
'Reply-To: '.$email . “\r\n” .
‘X-Mailer: PHP/’ . phpversion();
@ mail(“[email protected]”, $naslov,
$poruka, “From:” . $email . “\r\n” . $newsletter . “\r\n” . $trup . “\r\n” . $ime);

//AUTO RESPONCE MESSAGE
//Create main headers
$pporuka = “”;
$pporuka .= "Po?tovani ";
$pporuka .= $ime;
$pporuka .= ", hvala na vasem upitu u vezi proizvoda: ";
$pporuka .= $trup;
$pporuka .= ", javit cemo vas se u ?to kracem roku. ";
$pporuka .= "
Upitali ste nas slijedece: ";
$pporuka .= $poruka;
//E-mails subject
//Send the email
mail($email, $naslov, $pporuka, “From:” . “[email protected]”);
?>

Thank you for contacting us. We will be in touch with you very soon.

<?php } ?>[/php]

The error messages are on Croatian but you don’t have to bother with that…
The problem is that the default selected item is Please choose(translated to english) and I need in the formtoemail to say if the select(that list) is “Molim odaberite” --> please choose then send an error message like for other parameters… and if it is Trup #100 - Trup #114 then do nothing and submit form

I think there is a simple msolution but I can’t remember any -.-

Thank you in advance!

to get the form to remember what’s selected use an if statement in the option to check what was posted matches if so then select that item

[php]<option value=“Trup #T114” <?php if($_POST['select'] == 'Trup #T114'){ echo 'selected=selected';}?>>Trup #T114[/php]

You would need to add this for each line.

Thank you, but… could you help me a bit more and tell me where should I put those lines?
in what line in code :smiley:

Thank you

Sure:

[php]

>Molimo odaberite >Trup #T100 >Trup #T101 >Trup #T102 >Trup #T103 >Trup #T104 >Trup #T105 >Trup #T106 >Trup #T107 >Trup #T108 >Trup #T109 >Trup #T110 >Trup #T111 >Trup #T112 >Trup #T113 >Trup #T114

[/php]

I have already done that but…
I copied it on line 35, that line is under this:
[php] $ime = $_POST[‘ime’]; // required
$email = $_POST[‘email’]; // required
$naslov = $_POST[‘naslov’]; // required
$poruka = $_POST[‘poruka’]; // required
$select = $_POST[‘select’] ; // required
$newsletter = $_POST[‘newsletter’]; // not required[/php]

Should it go anywhere else?
Beacause when I upload it and test it, it says that there is a error on that line 35

Cant’ edit so…
This is the error I get:
Parse error: syntax error, unexpected ‘<’ in /home/a7264383/public_html/FormToEmail1.php on line 35
Where is that unexpected <? is it before option?

what’s the error? also whats on line 35? the code I gave you shouldn’t cause any errors

This is how the code looks now:

[php]

<?php if(isset($_POST['email'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "info@clm-pro-tk"; $email_subject = "Your email subject line"; function died($error) { // your error code can go here echo "Ispričavano se, prilikom pošiljanja vašeg upita smo pronašli pogrešku/e. "; echo "Pogreška/e će biti prikazane ispod.

"; echo $error."

"; echo "Vrni se i popravi.

"; die(); } // validation expected data exists if(!isset($_POST['ime']) || !isset($_POST['email']) || !isset($_POST['naslov']) || !isset($_POST['select']) || !isset($_POST['poruka'])) { died('Ispričavamo se, pronašli smo pogrešku prilikom slanja vašeg upita.'); } $ime = $_POST['ime']; // required $email = $_POST['email']; // required $naslov = $_POST['naslov']; // required $poruka = $_POST['poruka']; // required $select = $_POST['select'] ; // required $newsletter = $_POST['newsletter']; // not required >Molimo odaberite >Trup #T100 >Trup #T101 >Trup #T102 >Trup #T103 >Trup #T104 >Trup #T105 >Trup #T106 >Trup #T107 >Trup #T108 >Trup #T109 >Trup #T110 >Trup #T111 >Trup #T112 >Trup #T113 >Trup #T114
 }
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';

if(!preg_match($email_exp,$email)) {
$error_message .= ‘E-mail ne valja.
’;
}
$string_exp = “/^[A-Za-z .’-]+$/”;
if(!preg_match($string_exp,$ime)) {
$error_message .= ‘Ime ne valja.
’;

}
if(strlen($naslov) < 2) {
$error_message .= ‘Naslov ne valja.
’;

}
if(strlen($poruka) < 2) {
$error_message .= ‘Poruka ne valja.
’;
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = “Form details below.\n\n”;

function clean_string($string) {
  $bad = array("content-type","bcc:","to:","cc:","href");
  return str_replace($bad,"",$string);
}

 
$email_message .= "Ime: ".clean_string($ime)."\n";
$email_message .= "Email: ".clean_string($email)."\n";
$email_message .= "Naslov: ".clean_string($naslov)."\n";
$email_message .= "Poruka: ".clean_string($poruka)."\n";

// create email headers
$headers = 'From: '.$email."\r\n".
'Reply-To: '.$email . “\r\n” .
‘X-Mailer: PHP/’ . phpversion();
@ mail(“[email protected]”, $naslov,
$poruka, “From:” . $email . “\r\n” . $newsletter . “\r\n” . $select . “\r\n” . $ime);

//AUTO RESPONCE MESSAGE
//Create main headers
$pporuka = “”;
$pporuka .= "Poštovani ";
$pporuka .= $ime;
$pporuka .= ", hvala na vasem upitu u vezi proizvoda: ";
$pporuka .= $select;
$pporuka .= ", javit cemo vas se u što kracem roku. ";
$pporuka .= "
Upitali ste nas slijedece: ";
$pporuka .= $poruka;
//E-mails subject
//Send the email
mail($email, $naslov, $pporuka, “From:” . “[email protected]”);
?>

Thank you for contacting us. We will be in touch with you very soon.

<?php } ?>[/php]

line 35:
[php]<option value=“Molimo odaberite” <?php if($_POST['select'] == 'Molimo odaberite'){ echo 'selected=selected';}?>>Molimo odaberite[/php]

The error:
Parse error: syntax error, unexpected ‘<’ in /home/a7264383/public_html/FormToEmail1.php on line 35

ah php needs closing before using HTML and opening after it

[php]

<?php if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "info@clm-pro-tk";
$email_subject = "Your email subject line";
 
 
function died($error) {
    // your error code can go here
    echo "Ispričavano se, prilikom pošiljanja vašeg upita smo pronašli pogrešku/e. ";
    echo "Pogreška/e će biti prikazane ispod.<br /><br />";
    echo $error."<br /><br />";
    echo "Vrni se i popravi.<br /><br />";
    die();
}
 
// validation expected data exists
if(!isset($_POST['ime']) ||
    !isset($_POST['email']) ||
    !isset($_POST['naslov']) ||
	!isset($_POST['select']) ||
    !isset($_POST['poruka'])) {
    died('Ispričavamo se, pronašli smo pogrešku prilikom slanja vašeg upita.');      
}
 
$ime = $_POST['ime']; // required
$email = $_POST['email']; // required
$naslov = $_POST['naslov']; // required
$poruka = $_POST['poruka']; // required
$select = $_POST['select'] ; // required
$newsletter = $_POST['newsletter']; // not required

?>

>Molimo odaberite >Trup #T100 >Trup #T101 >Trup #T102 >Trup #T103 >Trup #T104 >Trup #T105 >Trup #T106 >Trup #T107 >Trup #T108 >Trup #T109 >Trup #T110 >Trup #T111 >Trup #T112 >Trup #T113 >Trup #T114 <?php } $error_message = ""; $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; if(!preg_match($email_exp,$email)) { $error_message .= 'E-mail ne valja.
'; } $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$ime)) { $error_message .= 'Ime ne valja.
';

}
if(strlen($naslov) < 2) {
$error_message .= ‘Naslov ne valja.
’;

}
if(strlen($poruka) < 2) {
$error_message .= ‘Poruka ne valja.
’;
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = “Form details below.\n\n”;

function clean_string($string) {
  $bad = array("content-type","bcc:","to:","cc:","href");
  return str_replace($bad,"",$string);
}

 
$email_message .= "Ime: ".clean_string($ime)."\n";
$email_message .= "Email: ".clean_string($email)."\n";
$email_message .= "Naslov: ".clean_string($naslov)."\n";
$email_message .= "Poruka: ".clean_string($poruka)."\n";

// create email headers
$headers = 'From: '.$email."\r\n".
'Reply-To: '.$email . “\r\n” .
‘X-Mailer: PHP/’ . phpversion();
@ mail(“[email protected]”, $naslov,
$poruka, “From:” . $email . “\r\n” . $newsletter . “\r\n” . $select . “\r\n” . $ime);

//AUTO RESPONCE MESSAGE
//Create main headers
$pporuka = “”;
$pporuka .= "Poštovani ";
$pporuka .= $ime;
$pporuka .= ", hvala na vasem upitu u vezi proizvoda: ";
$pporuka .= $select;
$pporuka .= ", javit cemo vas se u što kracem roku. ";
$pporuka .= "
Upitali ste nas slijedece: ";
$pporuka .= $poruka;
//E-mails subject
//Send the email
mail($email, $naslov, $pporuka, “From:” . “[email protected]”);
?>

Thank you for contacting us. We will be in touch with you very soon.

<?php } ?>

[/php]

and i also had to add the <?php after that code
but now when I submt the form… it shows all the “trup’s” and highlight which one was selected and I don’t want that
I just want when the “Molimo izaberite” is selected to write down the error to go back and to select a product

ah sorry in that case you don’t need the if statements in the select just a single check will do:

[php]
if($select == ‘Molimo odaberite’){
died(‘Ispričavamo se, pronašli smo pogrešku prilikom slanja vašeg upita.’);
}
[/php]

[php]

<?php if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "info@clm-pro-tk";
$email_subject = "Your email subject line";
 
 
function died($error) {
    // your error code can go here
    echo "Ispričavano se, prilikom pošiljanja vašeg upita smo pronašli pogrešku/e. ";
    echo "Pogreška/e će biti prikazane ispod.<br /><br />";
    echo $error."<br /><br />";
    echo "Vrni se i popravi.<br /><br />";
    die();
}
 
// validation expected data exists
if(!isset($_POST['ime']) ||
    !isset($_POST['email']) ||
    !isset($_POST['naslov']) ||
	!isset($_POST['select']) ||
    !isset($_POST['poruka'])) {
    died('Ispričavamo se, pronašli smo pogrešku prilikom slanja vašeg upita.');      
}
 
$ime = $_POST['ime']; // required
$email = $_POST['email']; // required
$naslov = $_POST['naslov']; // required
$poruka = $_POST['poruka']; // required
$select = $_POST['select'] ; // required
$newsletter = $_POST['newsletter']; // not required

if($select == 'Molimo odaberite'){
	died('Ispričavamo se, pronašli smo pogrešku prilikom slanja vašeg upita.');
}

}
$error_message = “”;
$email_exp = ‘/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+.[A-Za-z]{2,4}$/’;
if(!preg_match($email_exp,$email)) {
$error_message .= ‘E-mail ne valja.
’;
}
$string_exp = “/^[A-Za-z .’-]+$/”;
if(!preg_match($string_exp,$ime)) {
$error_message .= ‘Ime ne valja.
’;

}
if(strlen($naslov) < 2) {
$error_message .= ‘Naslov ne valja.
’;

}
if(strlen($poruka) < 2) {
$error_message .= ‘Poruka ne valja.
’;
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = “Form details below.\n\n”;

function clean_string($string) {
  $bad = array("content-type","bcc:","to:","cc:","href");
  return str_replace($bad,"",$string);
}

 
$email_message .= "Ime: ".clean_string($ime)."\n";
$email_message .= "Email: ".clean_string($email)."\n";
$email_message .= "Naslov: ".clean_string($naslov)."\n";
$email_message .= "Poruka: ".clean_string($poruka)."\n";

// create email headers
$headers = 'From: '.$email."\r\n".
'Reply-To: '.$email . “\r\n” .
‘X-Mailer: PHP/’ . phpversion();
@ mail(“[email protected]”, $naslov,
$poruka, “From:” . $email . “\r\n” . $newsletter . “\r\n” . $select . “\r\n” . $ime);

//AUTO RESPONCE MESSAGE
//Create main headers
$pporuka = “”;
$pporuka .= "Poštovani ";
$pporuka .= $ime;
$pporuka .= ", hvala na vasem upitu u vezi proizvoda: ";
$pporuka .= $select;
$pporuka .= ", javit cemo vas se u što kracem roku. ";
$pporuka .= "
Upitali ste nas slijedece: ";
$pporuka .= $poruka;
//E-mails subject
//Send the email
mail($email, $naslov, $pporuka, “From:” . “[email protected]”);
?>

Thank you for contacting us. We will be in touch with you very soon.

<?php } ?>

[/php]

Ooh thank you very much :smiley:
I thought it was a simple solution :smiley:
Thank you again :slight_smile:

Sponsor our Newsletter | Privacy Policy | Terms of Service