1) I have an HTML Form that post all the gathered information(I.e when the user enters the details and clicks on submit )it will post to the to the Php file for processing

2) The problem is when i am not passing any value to the date Fields I am getting the below error.

Errors: For date fields: is not a valid value for the type xsd:date

How can i make my Post to accept the Null value for the fields and have a successfully submit.


The value passing from my form for Date Fields, if there is no value in the field is string(0) "".How can i stop this error and post it sucessfully.


    <html xmlns="http://www.w3.org/1999/xhtml">
    <form class="form-horizontal" action="CandidateCreationPage.php" method="post" enctype="multipart/form-data">
<td class="label-cell"><label>First Name <span class="required-input letters-only">*</span></label></td>
<input class="required-field letters-only" type="text" name="firstname" id="first-name" maxlength="25" />
 <td class="label-cell"><label>Last Name <span class="required-input">*</span></label></td>
<input class="required-field letters-only" type="text" name="lastname" id="last-name" maxlength="30" />
 <td class="label-cell"><label>When (If Applicable)</label></td>
<input type="date" name="workedpreviouslywhen" id="worked-previously-when" />
 <td class="label-cell"><label>Available to Start</label></td>
<input type="date" name="availabletostart" id="available-to-start" />

Post PHP:

$fields = array (
'First_Name__c' => $_POST['firstname'],
'Last_Name__c' => $_POST['lastname'],
'Email__c'=> $_POST['email'],
**if (isset($_POST['workedpreviouslywhen']) || !ctype_space($_POST['workedpreviouslywhen']) || empty($_POST['workedpreviouslywhen'])) {
**if (isset($_POST['availabletostart']) || !ctype_space($_POST['availabletostart']) || empty($_POST['availabletostart'])) {
**if (isset($_POST['startdateone']) || !ctype_space($_POST['startdateone']) || empty($_POST['startdateone'])) {     'Start_Date_Work_Exp1__c'=>$_POST['startdateone'],
**if (isset($_POST['enddateone']) || !ctype_space($_POST['enddateone']) || empty($_POST['enddateone'])) {
**if (isset($_POST['startdatetwo']) || !ctype_space($_POST['startdatetwo']) || empty($_POST['startdatetwo'])) {                             
**if (isset($_POST['enddatetwo']) || !ctype_space($_POST['enddatetwo']) || empty($_POST['enddatetwo'])) {
**if (isset($_POST['startdatethree']) || !ctype_space($_POST['startdatethree']) || empty($_POST['startdatethree'])) {
**if (isset($_POST['enddatethree']) || !ctype_space($_POST['enddatethree']) || empty($_POST['enddatethree'])) {                                                 'End_Date_Prev_Wor_END_2__c'=>$_POST['enddatethree'],

1 Answer 1


From the sounds of things you want to do some PHP validation prior to posting? You'd want to do something like this, firstly getting your variables from $_POST[], validating things (in this instance, whether or not fields are empty), then if that's successful posting it.

You could do this using an errors array, adding errors if fields fail validation and then checking whether or not that array is empty. If it is, post the data, otherwise, display the errors.

Something like this?

$firstName = $_POST['firstname']; // Get variables
$lastName = $_POST['lastname'];
$errors = array(); // Create array

if ($_POST) { // Has the user clicked submit?
  if (empty($firstname) || empty($lastname)) { //Check if they're empty
    $errors[] = 'First and last name required!'; // Add error message to the errors array

  if (empty($errors)) {
    // Post to Salesforce
  else {
    foreach($errors as $error) {
      echo $error."<br><br>";

Hopefully that's a good enough explanation!

Edit Whilst this should work, it's not secure. You should look to performing other types of validation as well then match what you have in Salesforce. Field length, only accepting integers if it's a number field, only accepting URLs if it's a URL field etc...

Edit 2 From your comment:

The value passing from my form for Date Fields and currency fields if there is no value in the field

I would suggest one solution would be only to post data to Salesforce if it exists. You could do this a few ways, a simple way would be:

$fields = array (
  if (isset($_POST['firstname']) || !ctype_space($_POST['firstname']) || empty($_POST['firstname'])) {
    'First_Name__c' => $_POST['firstname'],

This is a pretty simple, long way of doing it. Firstly, isset($var) will check whether or not the variable is set and exists, ctype_space($var) will check whether or not the field is just white space. We use ! because we don't want it to contain just white space. However, this would return false if the field is empty hence we don't want anything empty.

Assuming all this passes, you'll then add that value to the $fields array.

There's cleaner ways of doing this, in fact you may even want to use a function, but this should avoid passing anything empty to Salesforce at all.

  • I am having the validation on the form .I maintaining two forms one for the user to fill and the other to post the Data to SF DC. For Example: In my form i put a validation saying if the field(Pick list ) value is yes then the field is mandatory in the form.but when the user submits my post is expecting this value and giving me the error.I have problem with only the Date and the currency fields
    – Donald
    Dec 23, 2015 at 16:11
  • The value passing from my form for Date Fields and currency fields if there is no value in the field is string(0) "" **.I am getting the error as **is not a valid value for the type xsd:date and for the currency fields is not valid for the type xsd:double.How can i stop this error and post it sucessfully
    – Donald
    Dec 23, 2015 at 16:43
  • @PraveenKumar see my edit.
    – Dan Jones
    Dec 24, 2015 at 9:20
  • I have implemented the solution said above .But I am getting the error ** Parse error: syntax error, unexpected 'if' (T_IF), expecting ')' in C:\xampp\htdocs\Salesforce\CandidateCreationPage.php on line 78 ** .Please see the updated post.php in my question.
    – Donald
    Dec 24, 2015 at 15:09
  • can you please review the code i have provided above
    – Donald
    Jan 4, 2016 at 17:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .