Print isset?

How do I print isset on this form? Thanks

[php]

<?php $var = $result['email']; if (!empty($var)) { if (isset($_POST['submit'])) { if(isset($_POST['answer']) && $_POST['answer'] == '2'){ $to = "$var"; // change to your email address $name = htmlspecialchars ($_POST['name']); $email = htmlspecialchars ($_POST['email']); $phone = htmlspecialchars ($_POST['phone']); $msg = htmlspecialchars ($_POST['msg']); $d = date('l dS \of F Y h:i:s A'); $sub = "My Domain RE:".$result['title'].""; $headers = "From: $name <$email>\n"; $headers .= "Content-Type: text/plain; charset=iso-8859-1\n"; $mes = "phone: ".$phone."\n"; $mes .= "Message: ".$msg."\n"; $mes .= "Name: ".$name."\n"; $mes .= 'Email: '.$email."\n"; $mes .= 'Date & Time: '.$d; mail($to, $sub, $mes, $headers); echo "<div align='center'Email Has Been Sent"; } else { echo "<div align='center'ANSWER does not match! "; } } echo "
Email: ".$result['contact']."




What is 2 + 2?
Answer:



";}?>[/php]

If you are wanting to place the result in your form of what was posted, you would use $_POST[“answer”]. isset is jsut a function that returns true or false

Answer: <input name=‘answer’ type=‘text’ id=‘answer’ size=‘3’ maxlength=‘3’ value=’".$_POST[‘answer’]."’" />

You can’t echo isset, its a function that tests to see if something is set, that’s why u see it a lot in if statements - if(isset($_POST[‘submit’])) {).

So what is it that you’re actually trying to print?

I understand now what the function does. The script prints all of the fields except the textarea. I can’t seem to print the textarea portion. Thank you again richei and xakaimpkx.

That’s actually untrue. If you print isset() where isset returns true, it will print 1 (boolean true typecasted to string). If you print isset() and isset() returns false, you get nothing (boolean false typecasted to string).

For your problem, a couple of things:

  • textarea’s value is inside the tag, not in the value attribute. So, obviously, if you use value=’".preg_replace(’/[^a-z-_0-9.:/]/i’,’’,$_POST[‘msg’])."’, your textarea will look empty
  • That regular expression strips anything that is non-alphanumeric, not a dot, not a colon; not a forward slash and not a hyphen. I doubt you want to do that to a message
  • The mail code itself looks okay.
Sponsor our Newsletter | Privacy Policy | Terms of Service