miniBB ® miniBB®
miniBB Support Forums
 | Forums | Register | Reply | Search | Statistics | Manual |
Custom Tutorials and Modifications miniBB Support Forums / Custom Tutorials and Modifications /   

making Location field (or other simple text field) mandatory

Author Anonymous
Guest
#1 | Posted: 21 Jun 2007 23:48 
When registering how do you make it so they must enter a Location?

Author Paul
Lead Developer
#2 | Posted: 22 Jun 2007 06:00 | Edited by: Paul 
I think the JavaScript solution would be the best and won't destroy the core files as well.

Apply the following changes modifying templates/user_dataform.html file:

1) at the very top, paste

<script type="text/javascript" src="{$main_url}/templates/form.js"></script>

2) In the section between JavaScript tags <script></script> paste new function:

function submitForm(){
var ind = document.forms['regform'];
if(trimTxt(ind.elements['login'].value)=='' || trimTxt(ind.elements['email'].value)=='' || (ind.elements['action'].value=='register' && (trimTxt(ind.elements['passwd'].value)=='' || trimTxt(ind.elements['passwd2'].value)=='') ) || trimTxt(ind.elements['from'].value)=='') { alert('Please, fill out all mandatory fields!'); return; }
else ind.submit();
}

3) Right after the variable {$warning} paste:

<noscript><br />JavaScript must be enabled to submit the profile!</noscript>


4) Replace the Submit button's code which says <input type="submit" value="{$userTitle}" class="inputButton" /> to:

<script type="text/javascript">
<!--
document.write('<input type="button" name="subbut" value="{$userTitle}" class="inputButton" onClick="submitForm();" />');
//-->
</script>


Now edit bb_plugins.php file and at the top of this file somewhere paste

/* Check location field */
if( ($action=='editprefs' OR $action=='register') and (!isset($_POST['from']) or trim($_POST['from'])=='') ) die('');

Any other mandatory text field may be implemented the same way...

Author Guest
#3 | Posted: 3 Apr 2012 05:18 
This only worked for me when I changed (input type="button") to (input type="submit")

Author Paul
Lead Developer
#4 | Posted: 3 Apr 2012 11:42 
I'm not sure which way it worked for you... "Submit" type of input sends the form immediately; with the "button" type you have a chance to validate all fields and perform other JavaScript checks before the form is submitted. That's my code above is about.

Custom Tutorials and Modifications miniBB Support Forums / Custom Tutorials and Modifications / making Location field (or other simple text field) mandatory Top

Your Reply Click this icon to move up to the quoted message

 Short link for this topic:

 ?
Only registered users are allowed to post here. Please, enter your username/password details upon posting a message, or register first.


Before posting, make sure your message is compliant with our forum posting rules. If not, it may be locked or deleted with no explanation.
 
miniBB Support Forums Powered by Forum Software miniBB ® Features  Requirements  Demo  Download  Showcase  Gallery of Arts
Compiler  Premium Extensions  Premium Support  License  Contacts
Check out the Captcha add-on: protect your miniBB-forums from the automated spam and flood.
Captcha Addon for miniBB