Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Anchor tag stripped from URL on form submit

Freeform version: 4.07 ExpressionEngine v2.5.3 - Build Date: 20120911

I have a freeform form inside a jQuery tab. When the form is submitted with erros, the anchor for that tab is stripped from the URL. This takes me back to the first tab and not the tab with the form in. Is there a way to redirect the user back to the form tab?

Thanks

<li id="qaTab">
  {exp:freeform:form
  form_id="2"
  required="name|email|user_message"
  return="contact_us/thank_you"
  recipients="yes"
  recipient1="Happy Harry|[email protected]"
  recipient2="Lazy Larry|[email protected]"
  recipient_template="contact_form"
  notify_user="yes"
  user_email_field="user_email"
  inline_errors="yes"
  }
   {if freeform:general_errors}
    <h2>There were some error(s) with your submission:</h2>
   <ul>
   {freeform:general_errors}
    <li>{freeform:error_message}</li>
   {/freeform:general_errors}
   </ul>
   {/if}
   <div class="row">
    <div class="six columns">
     <label>{freeform:label:name}</label>
     {freeform:field:name}
     {if freeform:error:name}<small class="error">{freeform:error:name}</small>{/if}
    </div>
    <div class="six columns">
     <label>{freeform:label:email}</label>
     {freeform:field:email}
     {if freeform:error:email}<small class="error">{freeform:error:email}</small>{/if}
    </div>
   </div>
   {freeform:label:user_message}
   {freeform:field:user_message}
   {if freeform:error:user_message}
   <small class="error">{freeform:error:user_message}</small>{/if}
   <input type="hidden" name="subject" value="{title}" id="subject">
   <input type="submit" name="submit" value="Submit" id="submit" class="button">
  {/exp:freeform:form}
 </li> 
like image 325
showFocus Avatar asked Oct 22 '12 12:10

showFocus


People also ask

Can you submit a form with an anchor tag?

To use the anchor tag as submit button, we need the help of JavaScript. To submit the form, we use JavaScript . submit() function. The function submits the form.

How do I stop form data from URL?

Inserting method="post" will stop the form from adding parameters in the URL. Save this answer.

How do you submit a hyperlink to a form?

In this article, we have submitted a form using JavaScript by clicking a link. In the body tag, created an HTML form and specify the id, method, and action of the form. In the form, specify an anchor tag with an event onclick. Create a function for JavaScript that will get executed when the link is clicked.

How do you prevent a form from clearing fields on submit?

You can use e. preventDefault() or return false; within a jQuery event handler: $("#Formid").


1 Answers

You should solve this using jQuery by:

  1. Checking for the existence of class error
  2. If exists: open the tab with the form
  3. Else: do nothing

Which would be something like:

if ($(".error").length > 0) {  
    $("#tabs").tabs("select", "#qaTab");
}

Good luck!

like image 121
Stoep Avatar answered Nov 15 '22 07:11

Stoep