update additional field form add/renew subscription page

Discussion in 'Customization & add-ons' started by rendersnag, May 14, 2011.

  1. rendersnag

    rendersnag Member

    Joined:
    Jan 28, 2011
    Messages:
    35
    Hello,

    On my signup page, i have added a addition field called 'date'. Which is working fine.
    But, I am looking for a way to update that additional 'date' field in the database, from the add/renew subscription form.

    I looked at the 'amembers_members' table and see that the additional fields are stored in the 'data' column as name/value pairs. How would i update this information?

    Is there a snippet of code I could add to a php page (member.php or signup.php), or to a certain function, that will include the additional field info when the subscription gets renewed?

    Any information would be greatly appreciated!
  2. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,274
  3. rendersnag

    rendersnag Member

    Joined:
    Jan 28, 2011
    Messages:
    35
    Hi Alexander,

    Thanks for that snippet of code! Would I add that to the do_renew function to update the data during a subscription renewal?

    Much appreciated...thank you!
  4. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,274
    No. This is better to use site.inc.php and finish_waiting_payment hook.
  5. rendersnag

    rendersnag Member

    Joined:
    Jan 28, 2011
    Messages:
    35
    Ok... have the 'fwp' function in the site.inc.php file, and the function is running because i see the printed output, but how do i pass the value of the form field from the member_add_renew.html template to line below?

    $user[data][fieldname] = "value";
  6. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,274
    It should be passed from renewal form and should be stored in member's profile?
    It will be updated when user will renew subscription and there will be only one value per user, is this correct? Sorry not sure I understood how this can be used, so want to confirm. may be you need separate field for each payment user complete?
  7. rendersnag

    rendersnag Member

    Joined:
    Jan 28, 2011
    Messages:
    35
    hi alexander,

    i could not get the $user[data][date] to update when using the site.inc.php file. so i placed your snippet of code in the do_renew() function in member.php and now it updates the database along with the membership renewal.

    I know updating member.php is bad practice due to updating reasons, but i couldnt get the finish_waiting_payment hook to work in site.inc.php. the function ran but the additional date field was not updated.

    basically, i have a membership that lasts 24 hours, and when you sign up, you have to pick a date for the membership, the date is an additional field. when you renew that membership, you need to pick a new date, so i needed to update the data.date field in the database. which i have working right now, but not in the best way.

    I do thank you for your help! I also have another question that pertains to this, but let me know if i should start a new thread for it.

    Here goes...

    When you sign up for a 24 hour membership, you need to pick a date. I have a jquery date picker to fill in the input field. I can disable dates in the date picker with an array of dates. So what I need to do is this:

    select all members that have an active 24 hour membership and grab the additional field called date (data.date), and put those dates into an array. from there i can push that array into the jquery date picker to disable the dates that are already taken.

    here is a link for visual reference if you don't mind taking a look...
    http://renderfeed.com/amember/signup1_day.php?price_group=12

    i hope this made some sort of sense, and once again, thanks for your help!
  8. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,274
    You can use this code in order to select dates for all active memberships.
    PHP:
    $q $db->query("select * from amember_members where status=1"); 
    $dates = array();
    while(
    $res mysql_fetch_assoc($q)){
      
    $data  unserialize($res[data]);
      
    $dates[$data[date]]=1;
    }
    return 
    array_keys($dates);
  9. rendersnag

    rendersnag Member

    Joined:
    Jan 28, 2011
    Messages:
    35
    Hi Alexander,

    Thanks for that handy snippet of code! I have yet to try to work it in...

    I need to pull the dates array into member.html and signup.html templates. Would i put this code in the site.inc.php and use the smarty code to grab the array value?
  10. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,274
    Define function in site.inc.php:
    PHP:
    function get_dates(){
    global 
    $db
    $q $db->query("select * from amember_members where status=1"); 
    $dates = array();
    while(
    $res mysql_fetch_assoc($q)){
      
    $data  unserialize($res[data]);
      
    $dates[$data[date]]=1;
    }
    return 
    array_keys($dates); 
    }
    Then use it in smarty template:
    PHP:
    {php}
    $dates get_dates();
    $this->assign("dates"$dates);
    {/
    php}
    Then in template you can use {$dates} array as regular smarty array.
  11. rendersnag

    rendersnag Member

    Joined:
    Jan 28, 2011
    Messages:
    35
    Hi Alexander,

    The snippet code returns an array of dates, correct?

    Am I able to grab this array and send the results to a page outside of amember? I have a signup form with a datepicker on it and want to use that array of dates to disable days in the datepicker. Is that possible?

    Thanks in advance!
  12. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,274
    Sure, possible.
    If you have php page, include amember config to access $db->query function.
    Then add this code:
    PHP:
    function get_dates(){
    global 
    $db
    $q $db->query("select * from amember_members where status=1"); 
    $dates = array();
    while(
    $res mysql_fetch_assoc($q)){
      
    $data  unserialize($res[data]);
      
    $dates[$data[date]]=1;
    }
    return 
    array_keys($dates); 
    }  
    $dates get_dates();

Share This Page