Check if form field is empty

Hi,

Is there a way to check if a form filled is empty or not?

I want to use the autopilot snippet, but that will depend if the the form field is empty or not. So it will either start from the first field, or the second one.

I tried using the click element, but i don't know if that's possible or if it's even the right path.

Hi Mike,

Yes, check for "". The syntax for the check would be - {if: variable=""}. You would need to assign a variable to your form first.

This check is often used with the error codes to ensure that a field, like first name has been entered.

Hi {formtext: name=client},{if: client=""}{error: don't forget a name; block=yes}{endif}

Please feel free to share what you are creating and we would be happy to help you troubleshoot.

Cheers,

Mike

Thanks @Mike_Burda for the help.

I should have been more explicit, i'm trying to target an online form.
Something like a contact form if you will. I want to check if one field is filled or not and depending on that a snippet or another will be used.

Hey @Mike85 , @Mike_Burda is offline so I'll answer your query meanwhile. Please give more details, specifically:

  1. is that form field a textbox or a checkbox?
  2. is it already filled before you run the snippet or does it get filled by your snippet?

A screenshot of its HTML code would be most helpful. Can you do the following steps:

  1. Right-click inside the form field (which you're trying to check for emptiness)
  2. Select the "Inspect" option - which is usually the last option in the menu.
  3. A panel will open on the right side.
  4. Now take a screenshot of the Chrome window

You can paste the screenshot here or if you prefer you can email it to me at gaurang@blaze.today

Hi @Gaurang_Tandon, thank you for the assist.

It's a textbox/textarea that i wish to check.
I wish to check if the field (textbox) is empty or not, that way i can use one snippet or another.

I can't give you the specific HTML, so screenshotted the textbox that i'm writing in right now. That should be fine, right? (you can further inspect it since it's here)

Check_if_form_field_is_empty_-Questions_and_Help - (Friday 21-June-2024)

Okay, a snippet like this should work then:

{current_value={site: text; selector=textarea.d-editor-input}}
{if: len(trim(current_value)) = 0}
{import: /emptysnippet}
{else}
{import: /nonemptysnippet}
{endif}

Worked like a charm, thank you so much!

Your post can be marked as solution.