Note that there are some explanatory texts on larger screens.

plurals
  1. PO$_POST Returning "Undefined index"
    primarykey
    data
    text
    <p>I know this question has been asked a lot, but none of the solutions work for me!</p> <p><strong>Please read the edit below first!</strong></p> <p>I'm relatively new to PHP, and I am creating a simple contact form:</p> <p><strong>HTML</strong>:</p> <pre><code>&lt;form action="contactUsSuccess.php" id="contactForm" method="post" name="contactForm" onsubmit="return validateContactUs();"&gt; &lt;table&gt; &lt;tr&gt; &lt;td&gt; &lt;input id="name" maxlength="70" name="name" placeholder="Name" type="text"&gt; &lt;/td&gt; &lt;td&gt; &lt;input id="email" maxlength="255" name="email" placeholder="Email" type="text"&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td colspan="2"&gt; &lt;textarea id="message" maxlength="5000" name="message" placeholder="Message"&gt;&lt;/textarea&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td colspan="2" id="submitArea"&gt; &lt;input id="submitButton" type="submit" value="Send"&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/form&gt; </code></pre> <p><strong>PHP</strong>, which is on <em>another page</em>.</p> <pre><code>&lt;?php $success = false; $name = $_POST["name"]; $email = $_POST["email"]; $message = $_POST["message"]; $to = "----@gmail.com"; $subject = "New Contact Message - ----"; $messageMail = "From: " . $name . "(" . $email . ")" . " | Message: " . $message; $header = "From: ----@gmail.com"; if(mail($to, $subject, $messageMail, $header)) { $success = true; } ?&gt; </code></pre> <p>My error:</p> <pre><code>Notice: Undefined index: name in Z:\Documents\Workspace\----\help\contactUsSuccess.php on line 6 Notice: Undefined index: email in Z:\Documents\Workspace\----\help\contactUsSuccess.php on line 7 Notice: Undefined index: message in Z:\Documents\Workspace\----\help\contactUsSuccess.php on line 8 </code></pre> <p>As you may be able to see, my form's <code>onsubmit</code> executes JavaScript, which just returns true or false. If you think for any reason that may be the reason why this isn't working, just ask.</p> <p>Also, I've tried the same PHP code that is shown above and put it in the same file as the original HTML (and also surrounding it with <code>isset</code> if statements... no luck.</p> <p>Oh, and the email still sends... it just sends:</p> <blockquote> <p>From: () | Message:</p> </blockquote> <p><strong>Edit:</strong> So it was the JavaScript! Here is the main part of it:</p> <pre><code>if (!(nameLen &gt; 0 &amp;&amp; nameLen &lt;= 70 &amp;&amp; emailLen &gt; 0 &amp;&amp; emailLen &lt;= 255 &amp;&amp; messageLen &gt; 0 &amp;&amp; messageLen &lt;= 5000)) { cont = false; } else { name.disabled = "true"; email.disabled = "true"; message.disabled = "true"; document.getElementById("submitButton").disabled = "true"; } if (cont) { return true; } else { return false; } } </code></pre> <p>When I removed the 3 <code>--.disabled = "true";</code>, it worked! However, I did have them in there for a reason. Is there an alternative? I guess this is what I'm asking for now...</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload