Passing variables between Forms

What I’m trying to do:
I’m trying to allow a phone number entered on my “Admin_Page” Form, be used in my “User_Page” Form.

Basically, I just want to be able to pass variables (self.text_box_1.text) back and forth between Forms.

What I’ve tried and what’s not working:
I’ve tried replicating the code here (Efficiently passing information from one form to another), but it’s erroring out on me. I get an error NameError: name ‘Admin_Page’ is not defined).

Code Sample:

#Client Side, Admin_Page Form:
  def text_box_1_pressed_enter(self, **event_args):
    result = alert(
               title=f"Is {self.text_box_1.text} the correct number?",
               large=True,
               buttons=[
                 ("Yes", "YES"),
                 ("No", "NO")])
    if result == "YES":
      alert(f"Thanks! Let's send messages from {self.text_box_1.text}.")
    else:
      alert("No problem, please enter the number you wish to text from and hit enter.")
    pass

#Client Side, User_Form Form:
  def send_text_click(self, **event_args):
    with anvil.server.no_loading_indicator:
      anvil.server.call('send_text', str(self.drop_down_1.selected_value),open_form('Admin_Page')['self.text_box_1.text'])
    pass

#Server Side:
@anvil.server.callable
def send_text(my_text, from_number):
    client.messages.create(to="+01231231234",
    body=(my_text),
    from_=from_number)


Clone link:
share a copy of your app

Anvil Docs | Creating Modules

You might wanna check out the docs

1 Like

Yep, I read through the Creating Modules section.

Hi! Sharing a clone link of an app that exhibits the problem (not necessarily the app you first noticed it in, since that might contain sensitive data or proprietary code) would really help for debugging purposes, so we can see exactly what’s going on.

1 Like

Thanks @eli-anvil!

Perhaps I can simplify a bit. How would I write the value contained in:

self.text_box_1.text

to a variable in a module named my_globals?

And how would I read it from a different form?

I think I’m getting stuck on the syntax.

Disregard, I figured it out. I’ve gone down a rabbit hole of learning about “state” in the last week. This is a heck of a learning experience! :smiley:

Thanks again!

1 Like