Store
Community Documentation

v3 Knowledgebase

Tutorial: Adding city field to registration form

Hi to all,

Today I searched the foruns for a solution to add the city field to the registration form, and didn't find one, although there where alot of posts asking for that. So I decided to investigate this and here is the solution:

ADD THE CITY FIELD TO THE TEMPLATE FORM

To do this you must search for the file step2.html.php

It's under this folder: module/user/template/default/block/register

Remember that if you don't use the default template then the file should be under the folder: module/user/template/[template name]/block/register

Open this file and add just after the location and before the timezone this code:
<div class="table">
<div class="table_left">
<label for="full_name">City:</label>
</div>
<div class="table_right">
<input  type="text" name="val[city]" id="city" value="{value type='input' id='city'}" size="30" autocomplete="off" />{required}
</div>			
</div>


MAKE THIS FIELD MANDATORY

To make the city field madatory just open the file register.class.php

It's under this folder module/user/include/service

And add this code:
$aValidation['city'] = 'You must add the city';


ADD THE FIELD DATA TO THE DB

Finaly you must add the field data to the database.

For that you must edit the file process.class.php

It's under the same folder: module/user/include/service

Open it and find this line of code:
$aExtras = array(
'user_id' => $iId
);


After that add this:
$aExtras1 = array(
'user_id' => $iId,
'city_location' => $aVals['city']
);


Then find this line of code:

$this->database()->insert(Phpfox::getT('user_field'), $aExtras);


And change the $aExtras for the $aExtras1 you setup before.

And that's it!

ENJOY!