ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Increment a global variable

September 19, 2013 12:08pm

Subscribe [2]
  • #1 / Sep 19, 2013 12:08pm

    Squeeze Digital

    5 posts

    We have a simple need for a unique ID to be submitted for every enquiry sent through a contact form on our site.

    This ID must be a sequential integer - much like a database ID.

    Can we assign “0” to a global variable called “EnquiryID” and then increment it in some way in template code?

    I can’t see any reference to writing global variables in template code.

    Or - any other solutions you can think of?

    Thanks

  • #2 / Sep 19, 2013 1:23pm

    Bhashkar Yadav

    727 posts

    Could you please share how you are submitting contact form? Are you using any module like FreeForm or Forms.

    The easy approach will be to make a hidden field for EnquiryID and put the incremented value with this form. The incremented value will be submitted each time with enquiry form.

  • #3 / Sep 20, 2013 4:21am

    Squeeze Digital

    5 posts

    Hi,

    We are posting the form to a template that contains PHP for mailing the form. No plugins are being used.

    The question is really about how we can access and update a global variable in template code - is it possible to update a variable from the template code in EE?

  • #4 / Sep 20, 2013 5:50am

    Bhashkar Yadav

    727 posts

    I think, here you are referring the EE Global Variables which will have the ID which would be incremented each time while submitting that Contact Form. Right?

    If so yes. As you are using the PHP code, then you can do the same with PHP code. Below is the code example which with you can update or increment by one the global variable.

    $sql = "UPDATE exp_global_variables SET variable_data = variable_data + 1 WHERE variable_name='[GLOBAL VARIABLE NAME WITHOUT BRACKET]'";
    
    ee()->db->query($sql);

    You would need to replace the variable_name with actual within WHERE condition.

    I hope, it would help you.

  • #5 / Sep 20, 2013 5:53am

    Squeeze Digital

    5 posts

    Thanks Bhashkar

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases