Jump to content

Custom Required Fields Allowance


servetas

Recommended Posts

  • Moderators

By default, the custom profile fields in phpVMS can't be set as required and most of us have issues when it comes to IVAO or VATSIM ids etc. Today, I decided to implement that feature. The changes can be found here. Let me list them here too:

1) On your database, go to your "TABLE_PREFIX"_customfields table and add a new column with the following details:

`required` smallint(6) NOT NULL DEFAULT '0'

2) On your core/templates/registration_customfields.php (or the custom one if you are using a custom template) find this:

<dt><?php echo $field->title; ?></dt>

and replace with this:

<dt><?php echo $field->title; ?><?php if($field->required == 1) echo ' *'; ?></dt>

find this:

else { ?>
	    <input type="text" name="<?php echo $field->fieldname; ?>" value="<?php echo Vars::POST($field->fieldname);?>" /></dd>
<?php }
}
}
?>

and replace with this:

else { ?>
	    <input type="text" name="<?php echo $field->fieldname; ?>" value="<?php echo Vars::POST($field->fieldname);?>" />
   <?php } ?>
       <?php if(${"custom_".$field->fieldname."_error"} == true) {
	    echo '<p class="error">Please enter your '.$field->title.'.</p>';
    }
    ?></dd>
<?php }
}
?>

3) On your admin/modules/PilotAdmin/PilotAdmin.php find this:

case 'saveprofile':
		    if ($this->post->firstname == '' || $this->post->lastname == '') {
			    $this->set('message', 'The first or lastname cannot be blank!');
			    $this->render('core_error.php');
			    return;
		    }

and this after that:

$fields = RegistrationData::getCustomFields();

	  if(count($fields) > 0) {
		  foreach ($fields as $field) {
			  $value = Vars::POST($field->fieldname);
			  $value1 = DB::escape($value);
			  if ($field->required == 1 && $value1 == '') {
   $this->set('message', ''.$field->title.' cannot be blank!');
   $this->render('core_error.php');
   return;
			  }
		  }
	  }

4) On your admin/modules/Settings/Settings.php find this (there should be two items):

'showinregistration'=>$this->post->showinregistration,

and replace it with this:

'showinregistration'=>$this->post->showinregistration,
  'required'=>$this->post->required

find this (there should be two items too):

if($data['showinregistration'] == 'yes')
  $data['showinregistration'] = true;
 else
  $data['showinregistration'] = false;

and add this after that:

if($data['required'] == 'yes')
  $data['required'] = true;
 else
  $data['required'] = false;

5) On your admin/templates/settings_addcustomfield.php find this:

<dt>Show During Registration</dt>
<dd>
 <select name="showinregistration">
 <option value="yes" <?php if($field->showonregister == 1) echo 'selected'; ?>>Yes</option>
 <option value="no" <?php if($field->showonregister == 0) echo 'selected'; ?>>No</option>
 </select>
</dd>

and add this after that:

<dt>Required</dt>
<dd>
 <select name="required">
 <option value="yes" <?php if($field->required == 1) echo 'selected'; ?>>Yes</option>
 <option value="no" <?php if($field->required == 0) echo 'selected'; ?>>No</option>
 </select>
</dd>

6) On your admin/templates/settings_customfieldsform.php find this:

<th>Default Value</th>

and add this after it:

<th>Required</th>

then find this:

<td align="center"><?php echo $field->value;?></td>

and add this after that:

<td align="center"><?php if($field->required == 1) {echo 'YES';} else {echo 'NO';} ?></td>

7) On your core/common/SettingsData.class.php find this (there should be two items):

if ($data['showinregistration'] == true) $data['showinregistration'] = 1;
    else  $data['showinregistration'] = 0;

and after that place this:

if ($data['required'] == true) $data['required'] = 1;
 else $data['required'] = 0;

Then find this:

$sql = "INSERT INTO " . TABLE_PREFIX .
	    "customfields (title, fieldname, value, type, public, showonregister)
 VALUES ('{$data['title']}', '$fieldname', '{$data['value']}', '{$data['type']}', {$data['public']}, {$data['showinregistration']})";

and replace it with this:

$sql = "INSERT INTO " . TABLE_PREFIX .
	    "customfields (title, fieldname, value, type, public, showonregister, required)
 VALUES ('{$data['title']}', '$fieldname', '{$data['value']}', '{$data['type']}', {$data['public']}, {$data['showinregistration']}, {$data['required']})";

Then find this:

$sql = "UPDATE " . TABLE_PREFIX . "customfields
   SET title='{$data['title']}', fieldname='{$fieldname}', value='{$data['value']}',
 type='{$data['type']}', public={$data['public']},
 showonregister={$data['showinregistration']}
   WHERE fieldid={$data['fieldid']}";

and replace it with this:

$sql = "UPDATE " . TABLE_PREFIX . "customfields
   SET title='{$data['title']}', fieldname='{$fieldname}', value='{$data['value']}',
 type='{$data['type']}', public={$data['public']},
 showonregister={$data['showinregistration']}, required={$data['required']}
   WHERE fieldid={$data['fieldid']}";

8) On your core/modules/Profile/Profile.php find this:

if($this->post->email == '') {
  return;
 }

and replace it with this:

if($this->post->email == '') {
  $this->set('message', 'The email address cannot be blank.');
  $this->render('core_error.php');
  return;
 }

 $fields = RegistrationData::getCustomFields();

 if(count($fields) > 0) {
	    foreach ($fields as $field) {
		    $value = Vars::POST($field->fieldname);
		    $value1 = DB::escape($value);
		    if ($field->required == 1 && $value1 == '') {
 $this->set('message', ''.$field->title.' cannot be blank!');
 $this->render('core_error.php');
 return;
		    }
	    }
    }

9) On your core/modules/Registration/Registration.php find this:

// Check is passwords are the same
 if($this->post->password1 != $this->post->password2) {
  $error = true;
  $this->set('password_error', 'The passwords do not match!');
 } else {
	    $this->set('password_error', '');
 }

and add the following after that:

//Get customs fields
    $fields = RegistrationData::getCustomFields();

    if(count($fields) > 0) {
	    foreach ($fields as $field) {
		    $value = Vars::POST($field->fieldname);
		    $value1 = DB::escape($value);
		    if ($field->required == 1 && $value1 == '') {
 $error = true;
			    $this->set('custom_'.$field->fieldname.'_error', true);
		    } else {
 $this->set('custom_'.$field->fieldname.'_error', '');
   }
	    }
    }

I hope that the changes are correct and I have not forgot anything. I have tested it on my localhost server but if any of you is interested to check that too, please let me know in case you spot any issue. I am going to submit a pull request to phpVMS 5.5.2 by David as soon as you confirm that it works ok. I will be happy to answer any of your questions.

George

PS: I would suggest to make the changes only if you have some basic knowledge about coding in order to avoid messing up things. And, as always, BACKUP. :)

  • Like 2
Link to comment
Share on other sites

Thanks Keith for your reply. Is there anyone else who has implemented it into his/her phpVMS? It would be nice to see if everything is ok. Then I will be sure to push a pull request on github

Yep, I can confirm that this works perfectly as well! Go ahead and make that pull request.

In the original post though, when you said there should be "two items" go me confused for a second (but did get there after processing it a few times ;) ), so you might want to mention that it should be in the add and edit (save) functions.

Edited by web541
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...