Note that there are some explanatory texts on larger screens.

plurals
  1. POHTML form doesn't collect data if one or more fields are empty
    text
    copied!<p>I've created a form for the user to fill out and on submit it is processed and stuff is done with it. Usually just a database query.</p> <p>With the database that I am working with, some fields can be NULL, so the user could leave something blank in some of the fields. However, when testing this, I tried having one or more fields empty, but the form wouldn't really submit anything at all. When I was debugging, almost all the values of the fields, even the ones with text in it, turn out NULL when I retrieve the values from the POST method.</p> <p>The thing is, I need to be able to allow the user to submit a form with some fields blank, as they are not completely necessary. How would I go about this?</p> <p>Do I have to check isset() for everything that could be blank and set it to NULL if it is?</p> <p>Thanks in advance!</p> <p>EDIT: Here is the form code.</p> <pre><code> &lt;form onsubmit="return confirm('Are you sure you want to save the edits?');" method="post" action="orgedit.php?id=&lt;?php echo $organization_id?&gt;" id="orgform" name="orgform" &gt; Parent Organization ID: &lt;input type="text" name="parent_id" value="&lt;?php echo $row['parent_id']; ?&gt;"/&gt; &lt;br /&gt;&lt;br /&gt; Organization nm: &lt;input type="text" name="org_nm" value="&lt;?php echo $row['org_nm']; ?&gt;"/&gt; &lt;br /&gt;&lt;br /&gt; TBR Organization Sysnm: &lt;input type="text" name="tbr_sysnm" value="&lt;?php echo $row['tbr_sysnm']; ?&gt;"/&gt; &lt;br /&gt;&lt;br /&gt; Type: &lt;input type="text" name="type" value="&lt;?php echo $row['type']; ?&gt;"/&gt; &lt;br /&gt;&lt;br /&gt; Contact nm: &lt;input type="text" name="contact_nm" value="&lt;?php echo $row['contact_nm']; ?&gt;"/&gt; &lt;br /&gt;&lt;br /&gt; Financial Info: &lt;input type="text" name="financial_info" value="&lt;?php echo $row['financial_info']; ?&gt;"/&gt; &lt;br /&gt;&lt;br /&gt; Other Info: &lt;input type="text" name="other_info" value="&lt;?php echo $row['other_info']; ?&gt;"/&gt; &lt;br /&gt;&lt;br /&gt; Active: &lt;input type="text" name="active" value="&lt;?php echo $row['active']; ?&gt;"/&gt; &lt;br /&gt;&lt;br /&gt; URL: &lt;input type="text" name="url" value="&lt;?php echo $row['url']; ?&gt;"/&gt; &lt;br /&gt;&lt;br /&gt; &lt;input type="submit" value="Save Entry" name="save" /&gt; &lt;/form&gt; </code></pre> <p>and here is the php processing code :)</p> <pre><code>if(isset($_GET['id'])) { $organization_id = $_GET['id']; $parent_organization_id = $_POST['parent_organization_id']; $organization_nm = $_POST['organization_nm']; $tbr_organization_sysnm = $_POST['tbr_organization_sysnm']; $type = $_POST['type']; $contact_nm = $_POST['contact_nm']; $financial_info = $_POST['financial_info']; $other_info = $_POST['other_info']; $active = $_POST['active']; $url = $_POST['url']; </code></pre> <p>After I get the values I simply escape them and perform a query.</p> <p>I have figured out the problem!</p> <pre><code>if(isset($_GET['id'])) { $organization_id = $_GET['id']; $parent_organization_id = $_POST['parent_id']; $organization_nm = $_POST['org_nm']; $tbr_organization_sysnm = $_POST['tbr_sysnm']; $type = $_POST['type']; $contact_nm = $_POST['contact_nm']; $financial_info = $_POST['financial_info']; $other_info = $_POST['other_info']; $active = $_POST['active']; $url = $_POST['url']; </code></pre> <p>I was retrieving the wrong values from the form. This could've been fixed by either changing the php code or the html code.</p> <p>The problem is, the one or more fields empty issue still persists. If one of the fields is blank, the entry is not saved. I've checked the logs and the message it outputted was:</p> <pre><code>PHP Notice: Undefined index: parent_id PHP Notice: Undefined index: org_nm PHP Notice: Undefined index: tbr_sysnm </code></pre> <p>This happens when I don't write anything for any of those fields and try to save the form.</p> <p>EDIT 2: The problem was fixed once again. Did a var dump and found that the server wasn't giving out anything when the code was trying to retrieve the values. It was a spelling mistake in a few of the fields.</p>
 

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