title: How to use " if(!empty($_POST[' .... '])){$.... = '-';} "?
body: <p>I do not understand why my code 'seems' to be incorrect.</p>
  
  <p>I got my .html form, like this:</p>
  
  <p>Part of my form:</p>
  
  <pre><code>&lt;input type="radio" name="going_to_order" value="Yes" id="going_to_order_yes"/&gt; Ja
  &lt;input type="radio" name="going_to_order" value="No" id="going_to_order_no"/&gt; nee
  </code></pre>
  
  <p>Part of my .js (Jquery)</p>
  
  <pre><code>$.post('mail.php',  
  {going_to_order:$("input[name=going_to_order]:checked").val()},
  </code></pre>
  
  <p>Part of my mail.php</p>
  
  <pre><code>$going_to_order = htmlspecialchars($_POST['going_to_order']);
  
  if(!empty($_POST['going_to_order'])){$going_to_order = 'xxx';}
  
  $message .=  "&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Is going to order?&lt;/strong&gt; &lt;/td&gt;&lt;td&gt;" . $going_to_order . "&lt;/td&gt;&lt;/tr&gt;";
  </code></pre>
  
  <p>If I comment out the <code>if(!empty))</code> line, i get the correct values <code>Yes</code> or <code>No</code>, but when leaving the radio button blank I get an <code>undefined</code> post.</p>
  
  <p>When the <code>if(!empty))</code> line is enabled, I only get the <code>xxx</code> value, regardless of whether or not the radio button is selected.</p>
  
  <p>Please help me to use <code>if(!empty))</code> correctly so that when a radio is selected I get the value, but if left blank, I don't see <code>undefined</code>.</p>
  
  <hr>
  
  <p>Edit: The PHP Code:</p>
  
  <pre><code>&lt;?php
  
  // Collect 'Algemeen'
  $algemene_rating = htmlspecialchars($_POST['algemene_rating']); 
  $gevonden_wat_u_zocht = htmlspecialchars($_POST['gevonden_wat_u_zocht']);
  $gaat_u_bestellen = htmlspecialchars($_POST['gaat_u_bestellen']);
  $wat_zocht_u = htmlspecialchars($_POST['wat_zocht_u']);
  $feedback_motivatie = htmlspecialchars($_POST['feedback_motivatie']);
  
  // Collect 'Fout'
  $fout_op_website = htmlspecialchars($_POST['fout_op_website']);
  $url_van_foutpagina = htmlspecialchars($_POST['url_van_foutpagina']);
  $fouturl_op_website = htmlspecialchars($_POST['fouturl_op_website']);
  $feedback_fout = htmlspecialchars($_POST['feedback_fout']);
  
  // Collect 'Compliment'
  $compliment_over_website = htmlspecialchars($_POST['compliment_over_website']);
  $feedback_compliment = htmlspecialchars($_POST['feedback_compliment']);
  
  // Collect 'Suggestie'
  $suggestie_geven = htmlspecialchars($_POST['suggestie_geven']);
  if ($_POST['suggestie_dienstverlening'] == "true")  {$suggestie_onderwerp_01 .= "&lt;li&gt; Dienstverlening &lt;/li&gt;";}
  if ($_POST['suggestie_opmaak'] == "true")           {$suggestie_onderwerp_02 .= "&lt;li&gt; Opmaak &lt;/li&gt;";}
  if ($_POST['suggestie_functionaliteit'] == "true")  {$suggestie_onderwerp_03 .= "&lt;li&gt; Functionaliteit &lt;/li&gt;";}
  if ($_POST['suggestie_site_inhoud'] == "true")      {$suggestie_onderwerp_04 .= "&lt;li&gt; Site inhoud &lt;/li&gt;";}
  if ($_POST['suggestie_anders'] == "true")           {$suggestie_onderwerp_05 .= "&lt;li&gt; Anders.. &lt;/li&gt;";}
  $feedback_suggestie = htmlspecialchars($_POST['feedback_suggestie']);
  
  // Collect 'Inhoud'
  $feedback_over_inhoud = htmlspecialchars($_POST['feedback_over_inhoud']);
  $feedback_over_inhoud_url = htmlspecialchars($_POST['feedback_over_inhoud_url']);
  $feedback_over_inhoud_url_klopt = htmlspecialchars($_POST['feedback_over_inhoud_url_klopt']);
  if ($_POST['inhoud_onjuiste_tekst'] == "true")      {$inhoud_onderwerp_01 .= "&lt;li&gt; Onjuiste Tekst &lt;/li&gt;";}
  if ($_POST['inhoud_schending_copyright'] == "true") {$inhoud_onderwerp_02 .= "&lt;li&gt; Schending Copyright &lt;/li&gt;";}
  if ($_POST['inhoud_ontbrekende_tekst'] == "true")   {$inhoud_onderwerp_03 .= "&lt;li&gt; Ontbrekende Tekst &lt;/li&gt;";}
  if ($_POST['inhoud_anders'] == "true")              {$inhoud_onderwerp_04 .= "&lt;li&gt; Anders.. &lt;/li&gt;";}
  $feedback_inhoud_tekst = htmlspecialchars($_POST['feedback_inhoud_tekst']);
  
  // Collect 'Producten'
  $feedback_producten = htmlspecialchars($_POST['feedback_producten']);
  $feedback_over_inhoud_url_klopt = htmlspecialchars($_POST['feedback_over_inhoud_url_klopt']);
  if ($_POST['product_onjuiste_ontbrekende_beschrijving'] == "true")  {$product_onderwerp_01 .= "&lt;li&gt; Onjuiste of ontbrekende tekst &lt;/li&gt;";}
  if ($_POST['product_fout_op_de_productpagina'] == "true")           {$product_onderwerp_02 .= "&lt;li&gt; Fout op de productpagina &lt;/li&gt;";}
  if ($_POST['product_missend_product'] == "true")                    {$product_onderwerp_03 .= "&lt;li&gt; Missend product &lt;/li&gt;";}
  if ($_POST['product_anders'] == "true")                             {$product_onderwerp_04 .= "&lt;li&gt; Anders.. &lt;/li&gt;";}
  $feedback_over_producten = htmlspecialchars($_POST['feedback_over_producten']);
  
  // if Collect '' = empty
  //if(empty($_POST['algemene_rating'])){$algemene_rating = '-';}
  //if(empty($_POST['gevonden_wat_u_zocht'])){$gevonden_wat_u_zocht   =   '-';}
  //if(empty($_POST['gaat_u_bestellen'])){$gaat_u_bestellen   =   '-';}
  //if(empty($_POST['fout_op_website'])){$fout_op_website =   '-';}
  //if(empty($_POST['fouturl_op_website'])){$fouturl_op_website   =   '-';}
  //if(empty($_POST['compliment_over_website'])){$compliment_over_website =   '-';}
  //if(empty($_POST['suggestie_geven'])){$suggestie_geven =   '-';}
  //if(empty($_POST['feedback_over_inhoud'])){$feedback_over_inhoud   =   '-';}
  //if(empty($_POST['feedback_over_inhoud_url_klopt'])){$feedback_over_inhoud_url_klopt   =   '-';}
  //if(empty($_POST['feedback_producten'])){$feedback_producten   =   '-';}
  
  
  
  //Collect 'Emailadres'
  $email = htmlspecialchars($_POST['email']);
  
  // Collect: 'Attributes'
  $tijd = time();
  $datum = strftime("%d/%m/%y %H:%M", $tijd);
  $ip = getenv("REMOTE_ADDR");
  
  // Collect 'Mail info'
  $headers = 'MIME-Version: 1.0' . "\r\n"; 
  $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 
  
  // Het bericht voor de ontvanger 
  $message = '&lt;html&gt;&lt;body&gt;';
  $message .= '&lt;table rules="all" style="background-color:#F8F8F8; width:600px; font-family:arial; font-size:11px; valign:top"&gt;';
  $message .= '&lt;table rules="all" border="1px solid #666666" style="background-color:#F8F8F8; width:600px; font-family:arial; font-size:11px;"&gt;';
  $message .= '&lt;td style="width:200px;"  /&gt;&lt;/td&gt;';
  $message .= "&lt;tr&gt;&lt;td&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/td&gt;&lt;td&gt;&lt;h3&gt;Feedbackformulier Multihout.nl&lt;/h3&gt;&lt;/td&gt;&lt;/tr&gt;";
  // 'Attributes'
  $message .=  "&lt;tr&gt;&lt;td&gt;&lt;hr/&gt;&lt;/td&gt;&lt;td&gt;&lt;hr/&gt;&lt;/td&gt;&lt;/tr&gt;";
  $message .=  "&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Feedback datum:&lt;/strong&gt; &lt;/td&gt;&lt;td&gt;        " . $datum . "&lt;/td&gt;&lt;/tr&gt;";
  $message .=  "&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Feedback e-mailadres:&lt;/strong&gt; &lt;/td&gt;&lt;td&gt;  " . $email . "&lt;/td&gt;&lt;/tr&gt;";
  $message .=  "&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Feedback IP-adres:&lt;/strong&gt; &lt;/td&gt;&lt;td&gt;     " . $ip . "&lt;/td&gt;&lt;/tr&gt;";
  // 'Algemeen'
  $message .=  "&lt;tr&gt;&lt;td&gt;&lt;hr/&gt;&lt;/td&gt;&lt;td&gt;&lt;hr/&gt;&lt;/td&gt;&lt;/tr&gt;";
  $message .=  "&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Algemene rating van de site:&lt;/strong&gt; &lt;/td&gt;&lt;td&gt;" . $algemene_rating . "&lt;/td&gt;&lt;/tr&gt;";
  $message .=  "&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Gevonden wat hij/zij zocht: &lt;/td&gt;&lt;td&gt;" . $gevonden_wat_u_zocht . "&lt;/td&gt;&lt;/tr&gt;";
  $message .=  "&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Gaat de klant bestellen?&lt;/strong&gt; &lt;/td&gt;&lt;td&gt;" . $gaat_u_bestellen . "&lt;/td&gt;&lt;/tr&gt;";
  $message .=  "&lt;tr&gt;&lt;td&gt;&lt;strong&gt;De klant zocht naar:&lt;/strong&gt; &lt;/td&gt;&lt;td&gt;" . $wat_zocht_u . "&lt;/td&gt;&lt;/tr&gt;";
  $message .=  "&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Feedback om niet te bestellen:&lt;/strong&gt; &lt;/td&gt;&lt;td&gt;" . $feedback_motivatie . "&lt;/td&gt;&lt;/tr&gt;";
  // 'Fout'
  $message .=  "&lt;tr&gt;&lt;td&gt;&lt;hr/&gt;&lt;/td&gt;&lt;td&gt;&lt;hr/&gt;&lt;/td&gt;&lt;/tr&gt;";
  $message .=  "&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Fout op de website?&lt;/strong&gt; &lt;/td&gt;&lt;td&gt;" . $fout_op_website . "&lt;/td&gt;&lt;/tr&gt;";
  $message .=  "&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Feedback over URL:&lt;/strong&gt; &lt;/td&gt;&lt;td&gt;" . $url_van_foutpagina . "&lt;/td&gt;&lt;/tr&gt;";
  $message .=  "&lt;tr&gt;&lt;td&gt;&lt;strong&gt;URL correct:&lt;/strong&gt; &lt;/td&gt;&lt;td&gt;" . $fouturl_op_website . "&lt;/td&gt;&lt;/tr&gt;";
  $message .=  "&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Feedback op de fout:&lt;/strong&gt; &lt;/td&gt;&lt;td&gt;" . $feedback_fout . "&lt;/td&gt;&lt;/tr&gt;";
  // 'Compliment'
  $message .=  "&lt;tr&gt;&lt;td&gt;&lt;hr/&gt;&lt;/td&gt;&lt;td&gt;&lt;hr/&gt;&lt;/td&gt;&lt;/tr&gt;";
  $message .=  "&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Is er een compliment?&lt;/strong&gt; &lt;/td&gt;&lt;td&gt;" . $compliment_over_website . "&lt;/td&gt;&lt;/tr&gt;";
  $message .=  "&lt;tr&gt;&lt;td&gt;&lt;strong&gt;De compliment:&lt;/strong&gt; &lt;/td&gt;&lt;td&gt;" . $feedback_compliment . "&lt;/td&gt;&lt;/tr&gt;";
  // Collect 'Suggestie'
  $message .=  "&lt;tr&gt;&lt;td&gt;&lt;hr/&gt; &lt;/td&gt;&lt;td&gt;&lt;hr/&gt;&lt;/td&gt;&lt;/tr&gt;";
  $message .=  "&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Een suggestie?&lt;/strong&gt; &lt;/td&gt;&lt;td&gt;" . $suggestie_geven . "&lt;/td&gt;&lt;/tr&gt;";
  $message .=  "&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Onderwerp suggestie:&lt;/strong&gt; &lt;/td&gt;&lt;td&gt;" . $suggestie_onderwerp_01 ."". $suggestie_onderwerp_02 ."". $suggestie_onderwerp_03 ."". $suggestie_onderwerp_04 ."". $suggestie_onderwerp_05 ."&lt;/td&gt;&lt;/tr&gt;";
  $message .=  "&lt;tr&gt;&lt;td&gt;&lt;strong&gt;De suggestie:&lt;/strong&gt; &lt;/td&gt;&lt;td&gt;" . $feedback_suggestie . "&lt;/td&gt;&lt;/tr&gt;";
  // Collect 'Inhoud'
  $message .=  "&lt;tr&gt;&lt;td&gt;&lt;hr/&gt;&lt;/td&gt;&lt;td&gt;&lt;hr/&gt;&lt;/td&gt;&lt;/tr&gt;";
  $message .=  "&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Feedback over de inhoud?&lt;/strong&gt; &lt;/td&gt;&lt;td&gt;" . $feedback_over_inhoud . "&lt;/td&gt;&lt;/tr&gt;";
  $message .=  "&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Feedback over URL:&lt;/strong&gt; &lt;/td&gt;&lt;td&gt;" . $feedback_over_inhoud_url . "&lt;/td&gt;&lt;/tr&gt;";
  $message .=  "&lt;tr&gt;&lt;td&gt;&lt;strong&gt;URL correct:&lt;/strong&gt; &lt;/td&gt;&lt;td&gt;" . $feedback_over_inhoud_url_klopt . "&lt;/td&gt;&lt;/tr&gt;";
  $message .=  "&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Feedback onderwerp:&lt;/strong&gt; &lt;/td&gt;&lt;td&gt;" . $inhoud_onderwerp_01 ."". $inhoud_onderwerp_02 ."". $inhoud_onderwerp_03 ."". $inhoud_onderwerp_04 ."&lt;/td&gt;&lt;/tr&gt;";
  $message .=  "&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Feedback over inhoud:&lt;/strong&gt; &lt;/td&gt;&lt;td&gt;" . $feedback_inhoud_tekst . "&lt;/td&gt;&lt;/tr&gt;";
  // Collect 'producten'
  $message .=  "&lt;tr&gt;&lt;td&gt;&lt;hr/&gt;&lt;/td&gt;&lt;td&gt;&lt;hr/&gt;&lt;/td&gt;&lt;/tr&gt;";
  $message .=  "&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Feedback over producten?:&lt;/strong&gt; &lt;/td&gt;&lt;td&gt;" . $feedback_producten . "&lt;/td&gt;&lt;/tr&gt;";
  $message .=  "&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Feedback onderwerp:&lt;/strong&gt; &lt;/td&gt;&lt;td&gt;" . $product_onderwerp_01 ."". $product_onderwerp_02 ."". $product_onderwerp_03 ."". $product_onderwerp_04 ."&lt;/td&gt;&lt;/tr&gt;";
  $message .=  "&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Feedback over product:&lt;/strong&gt; &lt;/td&gt;&lt;td&gt;" . $feedback_over_producten . "&lt;/td&gt;&lt;/tr&gt;";
  $message .=  "&lt;tr&gt;&lt;td&gt;&lt;hr/&gt;&lt;/td&gt;&lt;td&gt;&lt;hr/&gt;&lt;/td&gt;&lt;/tr&gt;";
  $message .= "&lt;/table&gt;";
  $message .= "&lt;/body&gt;&lt;/html&gt;"; 
  
  // Gedeelte voor het verzenden van het bericht
  $mailadres = "xx@mxx";
  $message = str_replace ("&lt;br&gt;","\n", $message);
  $headers .= "From: xx &lt;xx@exx.nl&gt;" . "\r\n";
  mail("$mailadres", "Nieuw bericht via mailformulier", $message, $headers); 
  
  ?&gt;
  &lt;!--Display a thankyou message in the callback --&gt;
  &lt;div id="mail_response"&gt;
      &lt;h3&gt;Thank you &lt;?php echo $name ?&gt;!&lt;/h3&gt;&lt;br /&gt;
      &lt;p&gt;I will answer your message soon as possible.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;
      &lt;h5&gt;Message sent on: &lt;/h5&gt;
      &lt;p&gt;&lt;?php  ?&gt;&lt;/p&gt;
  &lt;/div&gt;    
  </code></pre>