Joomla Client sends multiple requests to controller - joomla

I am using Joomla version 3.7.4
I have a form which sends a post request to a method called VerifyMe() in the controller. The form is like so:
<form action="myUrl" class="" method="post">
<input type="hidden" name="task" value="verifyUser"/>
<input type="hidden" name="method" value="<?php echo 'type' ?>"/>
<div class="row">
<div class="col-md-12 text-right">
<button type="submit" class="btn btn-default bold uppercase"><?php echo JText::_('SEND') ?></button>
</div>
</div>
</form>
And in my controller, I have the method
public function verifyMe()
{
JLog::add('VerifyMe Function called for '. $this->input->get('ID') , JLog::INFO, 'VerifyMe');
}
Now in the live environment, for some reason when the client clicks the submit button, the VerifyMe() function is called multiple times. This is not always the case but around 30% of the times its 2 or more calls for the same user.

I had the same problem, and I found the remedy.
Believe it or not, the solution is, tell the users not to "double-click" the buttons. Users tend to click web page buttons like they do to Windows icons.
If you really want to get rid of such problem, do some JavaScript to the template to disable the submit button on submit event.
Hope this helps.

Related

The PUT method is not supported for this route. Supported methods: GET, HEAD

I'm trying to learn Laravel, and I'm following a series of tutorials called laracast. I'm at episode 24, "Forms that submit PUT requests. The short story is that the markup uses a hidden value to set the method to PUT, although the forms method is set to POST. Still, when I do this, I get the error message from the title:
Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException
The PUT method is not supported for this route. Supported methods: GET, HEAD.
From the tutorials, I'd expect POST to also be a supported method. However, when I try to fix this, all resources I can find simply tells me what I already know. PUT is not supported, but I can fake it/override it, and then they refer to what I have already done... Are there any other reasons why I might get this error message?
HTML Form:
<form method="POST" action="/competition-categories">
#csrf
#method('PUT')
<div class="form-group row">
<label for="competition-category-name-input" class="col-4 col-form-label">Name</label>
<div class="col-8">
<input id="competition-category-name-input" name="competition-category-name-input" type="text" class="form-control" required="required" value="{{ $competitionCategory->name }}">
</div>
</div>
<div class="form-group row">
<label for="competition-category-abbreviation-input" class="col-4 col-form-label">Abbreviation</label>
<div class="col-8">
<input id="competition-category-abbreviation-input" name="competition-category-abbreviation-input" type="text" class="form-control" required="required" value="{{ $competitionCategory->abbreviation }}">
</div>
</div>
<div class="form-group row">
<div class="offset-4 col-8">
<button name="submit" type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
</form>
web.php snippet:
//Competition Categories
Route::get('/competition-categories', 'CompetitionCategoryController#index');
Route::get('/competition-categories/create', 'CompetitionCategoryController#create');
Route::get('/competition-categories/{competitionCategory}', 'CompetitionCategoryController#show');
Route::get('/competition-categories/{competitionCategory}/edit', 'CompetitionCategoryController#edit');
Route::post('/competition-categories/{competitionCategory}', 'CompetitionCategoryController#store');
Route::put('/competition-categories/{competitionCategory}', 'CompetitionCategoryController#udpate');
Route::delete('/competition-categories/{competitionCategory}', 'CompetitionCategoryController#destroy');
Snippet from the controller:
public function update(Request $request, CompetitionCategory $competitionCategory)
{
$competitionCategory->update($this->validateCompetitionCategory());
return redirect()->route('competition-categories' , [$competitionCategory]);
}
You're forgetting the id in form, this should fix your problem:
action="/competition-categories/{{$competitionCategory->id}}"
The most common thing that this happens is your cache. When you add a new route or change something in your routes, always run after php artisan optimize to refresh you cache.
I recommend using the named-routes for more informations and messages see =>
https://laravel.com/docs/7.x/routing#named-routes

use from has action but no call to route

when i click to button nothing happened.
code in html
<from action="{{route('add_to_card')}}" method="post">
{{csrf_field()}}
#method('PATCH')
<label>Quantity:</label>
<input name="qty" type="text" value="1"/>
<input type="hidden" name="product_id" value="{{$product_by_details->product_id}}">
<button type="submit" class="btn btn-fefault cart">
<i class="fa fa-shopping-cart"></i>
Add to cart
</button>
</from>
code in route
route::post('/add-to-cart','CartController#add_to_cart')->name('add_to_card');
code in controller
public function add_to_cart(Request $request)
{
echo"1";
}
Even when i echo something
In the line 20 of your file (Here)
Change <from> to <form> , you had typo error .
Do it for closig tag on line 30.
First of all please visit this site to have an idea on the naming conventions in laravel. This will help a lot and prevent future errors and to make your application more optimized.
Now for my answer, nothing happens when you click the button because you are using the tag <from> instead of <form>.
All you have to do is change the <from> tag to <form> tag.

thymeleaf 3 form action URL with parameters and get method not working

I am using Thymeleaf 3 in Spring Boot 2 web app. Below is the form code:
<form data-th-action="#{/props/r(pg=3)}" method="get">
<div class="form-check form-check-inline">
<input class="form-check-input" type="checkbox" name="pt" id="p1" value="pr">
<label class="form-check-label" for="p1">P1</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="checkbox" name="pt" id="p2" value="pr2">
<label class="form-check-label" for="p2">P2</label>
</div>
<button type="submit" class=" mb-4">Search</button>
</form>
Unfortunately when I used method get for the form, it does not append ?pg=3 in the submitted URL, the URL looks like /props/r? if no checkbox is selected. If checkbox is selected the URL looks like /props/r?pt=p1
the pg=3 part is missing.
How to fix this problem?
The problem is that you have an action #{/props/r(pg=3)} -- which translates to /props/r?pg=3 and your form is also method get. If you have parameters in both the action and the body of the form (and usemethod="get"), browsers will not combine them. Instead, the parameters of the action are removed and replaced with the paramters in the body of the form.
This is why ?pg=3 is removed and replaced with the checkbox parameters. Either use post instead, or include pg as a hidden form element.
Instead of putting pg as parameter at the form url, consider putting it inside a hidden field like below.
<input type="hidden" name="pg" value="3">

Gravity Forms Ajax Not Working

Using Gravity Forms 1.8.1 , no other plugins activated.
Tested also with latest build 1.9.2
Tested using Divi theme, as well as 2015 theme with same results.
Tested in Chrome and Firefox with same results.
Added the following shortcode:
[gravityform id="1" name="test-form-1" ajax="true"]
The form submits, but always with non-ajax and refreshes the page. I can tell this by looking at the tab and viewing the 'Net' tabs in Chrome's developer tools and Firebug in Firefox. The XHR requests are empty, and the requests clear and post normally as they would if it was a non-ajax request.
This should work. I get no errors or conflicts when looking at Firebug's console tab. I found no one experiencing similar problems although not really sure how many gravity form users are paying attention to the behavior in firebug.
I'm sure I'm missing something obvious. Let me know what it is!
Relevant form code generated by Gravity Forms
<div id="gform_wrapper_1" class="gf_browser_gecko gform_wrapper">
<a class="gform_anchor" name="gf_1" id="gf_1"></a>
<form action="/sandbox/#gf_1" id="gform_1" target="gform_ajax_frame_1" enctype="multipart/form-data" method="post">
<div class="gform_heading">
<h3 class="gform_title">test-form-1</h3>
<span class="gform_description"></span>
</div>
<div class="gform_body">
<ul class="gform_fields top_label description_below" id="gform_fields_1">
<li class="gfield gfield_contains_required" id="field_1_1">
<label for="input_1_1" class="gfield_label">Name<span class="gfield_required">*</span></label>
<div class="ginput_container"><input type="text" tabindex="1" class="medium" value="Joe Smith" id="input_1_1" name="input_1"></div>
</li>
</ul>
</div>
<div class="gform_footer top_label"> <input type="submit" onclick="if(window["gf_submitting_1"]){return false;} if( !jQuery("#gform_1")[0].checkValidity || jQuery("#gform_1")[0].checkValidity()){window["gf_submitting_1"]=true;} " tabindex="2" value="Submit" class="button gform_button" id="gform_submit_button_1"><input type="hidden" value="form_id=1&title=1&description=1&tabindex=1" name="gform_ajax">
<input type="hidden" value="1" name="is_submit_1" class="gform_hidden">
<input type="hidden" value="1" name="gform_submit" class="gform_hidden">
<input type="hidden" value="" name="gform_unique_id" class="gform_hidden">
<input type="hidden" value="WyJhOjA6e30iLCJkZjhiZTNiZTg3NDNmMWNlNDNmNTk1N2M0NTY2ZTRiMSJd" name="state_1" class="gform_hidden">
<input type="hidden" value="0" id="gform_target_page_number_1" name="gform_target_page_number_1" class="gform_hidden">
<input type="hidden" value="1" id="gform_source_page_number_1" name="gform_source_page_number_1" class="gform_hidden">
<input type="hidden" value="" name="gform_field_values">
</div>
</form>
</div>
You should still keep your scripts in the footer for performance reasons. But you need to include this in the header.php right above your <?php wp_head(); ?>:
<?php gravity_form_enqueue_scripts(1,true) ?>
with 1 being the id of the form.
In addition to Nate Beers answer, If you have a reCAPTCHA on your form AJAX will not work. reCAPTCHA is not compatible with AJAX.
See issue on gravity forms forum.
https://www.gravityhelp.com/forums/topic/ajax-submission-not-working-on-hard-coded-form#post-36914
I went ahead and used the Gravity Forms anti-spam honeypot as a reCAPTCHA alternative on the form settings page.
Make sure jQuery is enqueued in the head - not the footer.
I'm using the Roots/Sage framework in which it is enqueued in the footer by default - which was causing your exact issue.

Click a input type submit - Mechanize Ruby

I am trying to click a button which is actually a submit without a form which looks some thing like this and store the result in an object
<div class="searchBar-input">
<input id="front-page-search" value="Enter Keyword(s)" type="text">
</div>
<div class="searchBar-submit">
<input id="searchBtn" value="Search" type="submit">
</div>
I have tried puts page.forms and I am getting nothing as there is no form on the page. Its just a text box whose value I have to submit.
I have googled but I found everything about form submit and links. How can I click this? Any suggestions.Thanks in advance
try this :
<div class="searchBar-submit">
<input id="searchBtn" value="Search" type="submit" onclick="document.forms[0].submit();" ></div>

Resources