Autofill edit profile form question

13 years 4 months ago #146740 by sfraise
Autofill edit profile form question was created by sfraise
I've built a custom location dependent drop down for the registration and edit profile forms in order to have a uniform country, state, and city value for better search results.

It works fine, but an issue I'm running into is the values don't autofill with the user's data as the rest of the fields do in the edit profile form.

It seemed to me the easiest way to do this was to just create a text field in the cb admin called cb_city. I then created the dropdown selector using cb_city as the input name and id using ajax to pull the city values from txt files depending on what state is selected. I had to set it up this way as the values needed to only be called on fire of the parent (state) input, otherwise having all cities in all 50 states pulled all at page load would make the page load extremely slow obviously. Instead of showing the actual cb text field on the reg form or in the edit profile form I instead show the custom drop down selectors. When registering it works fine, the value is passed ok and displays fine on the profile front end. It also works fine in the edit profile form, but I really need the value to autofill with the users data already chosen just like the other fields.

I was going to go about creating a new sql query to work along with the custom selectors to try and pull the user's value but since this is obviously already done in cb I figured it would be easier and cleaner to use what's already there. I just don't know how to utilize it in what I've built.

I think it's just easiest to show how I've built this.
[code:1]
<label for="cb_state">State:<input class="inputbox AND DEPENDS ON cb_country BEING United States" type="hidden" /></label><label for="cb_caprovince">Province:<input class="DEPENDS ON cb_country BEING Canada" type="hidden" /></label><p></p> <label for="cb_state"> <select gtbfieldid="2676" name="cb_state" id="cb_state" onChange="handleOnChange(this);" class="inputbox"> <option> </option> <option value="Alabama" id="cbf85857">Alabama</option> <option value="Alaska" id="cbf85858">Alaska</option> <option value="Arizona" id="cbf85859">Arizona</option> <option value="Arkansas" id="cbf85860">Arkansas</option> <option value="California" id="cbf85861">California</option> <option value="Colorado" id="cbf85862">Colorado</option> <option value="Connecticut" id="cbf85863">Connecticut</option> <option value="Delaware" id="cbf85864">Delaware</option> <option value="District of Columbia" id="cbf85865">District of Columbia</option> <option value="Florida" id="cbf85866">Florida</option> <option value="Georgia" id="cbf85867">Georgia</option> <option value="Hawaii" id="cbf85868">Hawaii</option> <option value="Idaho" id="cbf85869">Idaho</option> <option value="Illinois" id="cbf85870">Illinois</option> <option value="Indiana" id="cbf85871">Indiana</option> <option value="Iowa" id="cbf85872">Iowa</option> <option value="Kansas" id="cbf85873">Kansas</option> <option value="Kentucky" id="cbf85874">Kentucky</option> <option value="Louisiana" id="cbf85875">Louisiana</option> <option value="Maine" id="cbf85876">Maine</option> <option value="Maryland" id="cbf85877">Maryland</option> <option value="Massachusetts" id="cbf85878">Massachusetts</option> <option value="Michigan" id="cbf85879">Michigan</option> <option value="Minnesota" id="cbf85880">Minnesota</option> <option value="Mississippi" id="cbf85881">Mississippi</option> <option value="Missouri" id="cbf85882">Missouri</option> <option value="Montana" id="cbf85883">Montana</option> <option value="Nebraska" id="cbf85884">Nebraska</option> <option value="Nevada" id="cbf85885">Nevada</option> <option value="New Hampshire" id="cbf85886">New Hampshire</option> <option value="New Jersey" id="cbf85887">New Jersey</option> <option value="New Mexico" id="cbf85888">New Mexico</option> <option value="New York" id="cbf85889">New York</option> <option value="North Carolina" id="cbf85890">North Carolina</option> <option value="North Dakota" id="cbf85891">North Dakota</option> <option value="Ohio" id="cbf85892">Ohio</option> <option value="Oklahoma" id="cbf85893">Oklahoma</option> <option value="Oregon" id="cbf85894">Oregon</option> <option value="Pennsylvania" id="cbf85895">Pennsylvania</option> <option value="Rhode Island" id="cbf85896">Rhode Island</option> <option value="South Carolina" id="cbf85897">South Carolina</option> <option value="South Dakota" id="cbf85898">South Dakota</option> <option value="Tennessee" id="cbf85899">Tennessee</option> <option value="Texas" id="cbf85900">Texas</option> <option value="Utah" id="cbf85901">Utah</option> <option value="Vermont" id="cbf85902">Vermont</option> <option value="Virginia" id="cbf85903">Virginia</option> <option value="Washington" id="cbf85904">Washington</option> <option value="West Virginia" id="cbf85905">West Virginia</option> <option value="Wisconsin" id="cbf85906">Wisconsin</option> <option value="Wyoming" id="cbf85907">Wyoming</option> </select> <input type="radio" name="cb_state___cbprivacy" mosReq="2" value="1" id="cb_state___cbprivacy0" /> <label for="cb_state___cbprivacy0">              </label>
<input type="radio" name="cb_state___cbprivacy" value="2" id="cb_state___cbprivacy1" /> <label for="cb_state___cbprivacy1">              </label>
<input type="radio" name="cb_state___cbprivacy" value="99" id="cb_state___cbprivacy2" /> <label for="cb_state___cbprivacy2"> </label>
 <span class='cbFieldIcons'></span></p>
<input class="inputbox AND DEPENDS ON cb_country BEING United States" type="hidden" /></label><label for="cb_caprovince"> <select gtbfieldid="2677" name="cb_caprovince" id="cb_caprovince" class="inputbox1"> <option> </option> <option value="Alberta" id="cbf66426">Alberta</option> <option value="British Columbia" id="cbf66427">British Columbia</option> <option value="Manitoba" id="cbf66428">Manitoba</option> <option value="New Brunswick" id="cbf66429">New Brunswick</option> <option value="NewFoundland" id="cbf66430">NewFoundland</option> <option value="North West Territories" id="cbf66431">North West Territories</option> <option value="Nova Scotia" id="cbf66432">Nova Scotia</option> <option value="Nunavut" id="cbf66433">Nunavut</option> <option value="Ontario" id="cbf66434">Ontario</option> <option value="Prince Edward Island" id="cbf66435">Prince Edward Island</option> <option value="Quebec" id="cbf66436">Quebec</option> <option value="Saskatchewan" id="cbf66437">Saskatchewan</option> <option value="Yukon" id="cbf66438">Yukon</option> </select> <input type="radio" name="cb_caprovince___cbprivacy" mosReq="2" value="1" id="cb_caprovince___cbprivacy0" /> <label for="cb_caprovince___cbprivacy0">              </label>
<input type="radio" name="cb_caprovince___cbprivacy" value="2" id="cb_caprovince___cbprivacy1" /> <label for="cb_caprovince___cbprivacy1">              </label>
<input type="radio" name="cb_caprovince___cbprivacy" value="99" id="cb_caprovince___cbprivacy2" /> <label for="cb_caprovince___cbprivacy2"> </label>
 <span class='cbFieldIcons'></span> </span><input class="DEPENDS ON cb_country BEING Canada" type="hidden" /></label>
<p><label for="cb_city">City:<input class="inputbox AND DEPENDS ON cb_state BEING Alabama OR cb_state BEING Alaska OR cb_state BEING Arizona OR cb_state BEING Arkansas OR cb_state BEING California OR cb_state BEING Colorado OR cb_state BEING Connecticut OR cb_state BEING Delaware OR cb_state BEING District of Columbia OR cb_state BEING Florida OR cb_state BEING Georgia OR cb_state BEING Hawaii OR cb_state BEING Idaho OR cb_state BEING Illinois OR cb_state BEING Indiana OR cb_state BEING Iowa OR cb_state BEING Kansas OR cb_state BEING Kentucky OR cb_state BEING Louisiana OR cb_state BEING Maine OR cb_state BEING Maryland OR cb_state BEING Massachusetts OR cb_state BEING Michigan OR cb_state BEING Minnesota OR cb_state BEING Mississippi OR cb_state BEING Missouri OR cb_state BEING Montana OR cb_state BEING Nebraska OR cb_state BEING Nevada OR cb_state BEING New Hampshire OR cb_state BEING New Jersey OR cb_state BEING New Mexico OR cb_state BEING New York OR cb_state BEING North Carolina OR cb_state BEING North Dakota OR cb_state BEING Ohio OR cb_state BEING Oklahoma OR cb_state BEING Oregon OR cb_state BEING Pennsylvania OR cb_state BEING Rhode Island OR cb_state BEING South Carolina OR cb_state BEING South Dakota OR cb_state BEING Tennessee OR cb_state BEING Texas OR cb_state BEING Utah OR cb_state BEING Vermont OR cb_state BEING Virginia OR cb_state BEING Washington OR cb_state BEING West Virginia OR cb_state BEING Wisconsin OR cb_state BEING Wyoming" type="hidden" /></label><p></p>

<label for="cb_city"> <select name="cb_city" id="cb_city" class="inputbox">
<option value=""> </option>
</select> <input type="radio" name="cb_city___cbprivacy" mosReq="2" value="1" id="cb_city___cbprivacy0" /> <label for="cb_city___cbprivacy0">              </label>
<input type="radio" name="cb_city___cbprivacy" value="2" id="cb_city___cbprivacy1" /> <label for="cb_city___cbprivacy1">              </label>
<input type="radio" name="cb_city___cbprivacy" value="99" id="cb_city___cbprivacy2" /> <label for="cb_city___cbprivacy2"> </label>
 <span class='cbFieldIcons'></span></p>

<input class="inputbox1 AND DEPENDS ON cb_state BEING Alabama OR cb_state BEING Alaska OR cb_state BEING Arizona OR cb_state BEING Arkansas OR cb_state BEING California OR cb_state BEING Colorado OR cb_state BEING Connecticut OR cb_state BEING Delaware OR cb_state BEING District of Columbia OR cb_state BEING Florida OR cb_state BEING Georgia OR cb_state BEING Hawaii OR cb_state BEING Idaho OR cb_state BEING Illinois OR cb_state BEING Indiana OR cb_state BEING Iowa OR cb_state BEING Kansas OR cb_state BEING Kentucky OR cb_state BEING Louisiana OR cb_state BEING Maine OR cb_state BEING Maryland OR cb_state BEING Massachusetts OR cb_state BEING Michigan OR cb_state BEING Minnesota OR cb_state BEING Mississippi OR cb_state BEING Missouri OR cb_state BEING Montana OR cb_state BEING Nebraska OR cb_state BEING Nevada OR cb_state BEING New Hampshire OR cb_state BEING New Jersey OR cb_state BEING New Mexico OR cb_state BEING New York OR cb_state BEING North Carolina OR cb_state BEING North Dakota OR cb_state BEING Ohio OR cb_state BEING Oklahoma OR cb_state BEING Oregon OR cb_state BEING Pennsylvania OR cb_state BEING Rhode Island OR cb_state BEING South Carolina OR cb_state BEING South Dakota OR cb_state BEING Tennessee OR cb_state BEING Texas OR cb_state BEING Utah OR cb_state BEING Vermont OR cb_state BEING Virginia OR cb_state BEING Washington OR cb_state BEING West Virginia OR cb_state BEING Wisconsin OR cb_state BEING Wyoming" type="hidden" /></label>
[/code:1]

I'm assuming it should be as simple as value="<?php echo $variable; ?>" but I don't know

Post edited by: sfraise, at: 2010/11/21 23:41

Please Log in to join the conversation.

13 years 4 months ago #146745 by sfraise
Replied by sfraise on topic Re:Autofill edit profile form question
I went ahead and just did it this way:
[code:1]
<?
global $_CB_framework, $_CB_database, $ueConfig, $mainframe, $_SERVER;
$query = "SELECT cb_state FROM #__comprofiler WHERE id = ". (int) $_CB_framework->myId();
$_CB_database->setQuery( $query );
$state = htmlspecialchars( cbUnHtmlspecialchars( $_CB_database->loadResult() ) );
$query = "SELECT cb_caprovince FROM #__comprofiler WHERE id = ". (int) $_CB_framework->myId();
$_CB_database->setQuery( $query );
$caprovince = htmlspecialchars( cbUnHtmlspecialchars( $_CB_database->loadResult() ) );
$query = "SELECT cb_city FROM #__comprofiler WHERE id = ". (int) $_CB_framework->myId();
$_CB_database->setQuery( $query );
$city = htmlspecialchars( cbUnHtmlspecialchars( $_CB_database->loadResult() ) );
?>
[/code:1]
Then just added the <?php echo $variable; ?> between the default <option> </option>.

It's kind of crude and although it does do the job, there is a glitch in doing it this way. In order to actually pull the other values you have to change the parent selector, otherwise the only option you will have is the one already selected, once you change the parent selector then it loads the other options. I'm sure I figure something out on that, probably something I can add to the ajax script.

What a pain in the butt this has been, it seems like such a simple thing to just add in dependent drop down selectors but it seems like every time I solve one issue I get another lol. I have to say getting the custom registration form in a jquery drop down panel and the edit profile form just as I need it has been one of the most difficult things I've ever tried to do in community builder or joomla.

Post edited by: sfraise, at: 2010/11/22 05:04

Please Log in to join the conversation.

13 years 4 months ago #146804 by krileon
Replied by krileon on topic Re:Autofill edit profile form question

I have to say getting the custom registration form in a jquery drop down panel and the edit profile form just as I need it has been one of the most difficult things I've ever tried to do in community builder or joomla.

Edit profile can be rendered with API, so it's like 5 lines of code. Registration can be loaded in an iframe avoiding any custom coding necessary. I suppose it'd be a pain if you want to alter the HTML it self, but I wouldn't recommend that as it'll probably stop working with each subsequent release.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.192 seconds

Facebook Twitter LinkedIn