I use the laravelcollective/html form, and i opend the form
{!! Form::open(['role' => 'form']) !!}
and closing
{!! Form::close() !!}
and of course the contect inside, the problem is that the output is like text
<form method="POST" action="http://localhost/Users/public" accept-charset="UTF-8" role="form">
There is no problem in your form but make sure you are using it in filename.blade.php, .blade.php is important or you can always use simple html5 forms in any case :)
Related
I have a form with id theForm which has the following div with a submit button inside:
<div id="placeOrder"
style="text-align: right; width: 100%; background-color: white;">
<button type="submit"
class='input_submit'
style="margin-right: 15px;"
onClick="placeOrder()">Place Order
</button>
</div>
When clicked, the function placeOrder() is called. The function changes the innerHTML of the above div to be "processing ..." (so the submit button is now gone).
The above code works, but now the problem is that I can't get the form to submit! I've tried putting this in the placeOrder() function:
document.theForm.submit();
But that doesn't work.
How can I get the form to submit?
Set the name attribute of your form to "theForm" and your code will work.
You can use...
document.getElementById('theForm').submit();
...but don't replace the innerHTML. You could hide the form and then insert a processing... span which will appear in its place.
var form = document.getElementById('theForm');
form.style.display = 'none';
var processing = document.createElement('span');
processing.appendChild(document.createTextNode('processing ...'));
form.parentNode.insertBefore(processing, form);
It works perfectly in my case.
document.getElementById("form1").submit();
Also, you can use it in a function as below:
function formSubmit()
{
document.getElementById("form1").submit();
}
document.forms["name of your form"].submit();
or
document.getElementById("form id").submit();
You can try any of this...this will definitely work...
I will leave the way I do to submit the form without using the name tag inside the form:
HTML
<button type="submit" onClick="placeOrder(this.form)">Place Order</button>
JavaScript
function placeOrder(form){
form.submit();
}
You can use the below code to submit the form using JavaScript:
document.getElementById('FormID').submit();
<html>
<body>
<p>Enter some text in the fields below, and then press the "Submit form" button to submit the form.</p>
<form id="myForm" action="/action_page.php">
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br><br>
<input type="button" onclick="myFunction()" value="Submit form">
</form>
<script>
function myFunction() {
document.getElementById("myForm").submit();
}
</script>
</body>
</html>
HTML
<!-- change id attribute to name -->
<form method="post" action="yourUrl" name="theForm">
<button onclick="placeOrder()">Place Order</button>
</form>
JavaScript
function placeOrder () {
document.theForm.submit()
}
If your form does not have any id, but it has a class name like theForm, you can use the below statement to submit it:
document.getElementsByClassName("theForm")[0].submit();
I have came up with an easy resolve using a simple form hidden on my website with the same information the users logged in with. Example: If you want a user to be logged in on this form, you can add something like this to the follow form below.
<input type="checkbox" name="autologin" id="autologin" />
As far I know I am the first to hide a form and submit it via clicking a link. There is the link submitting a hidden form with the information. It is not 100% safe if you don't like auto login methods on your website with passwords sitting on a hidden form password text area...
Okay, so here is the work. Let’s say $siteid is the account and $sitepw is password.
First make the form in your PHP script. If you don’t like HTML in it, use minimal data and then echo in the value in a hidden form. I just use a PHP value and echo in anywhere I want pref next to the form button as you can't see it.
PHP form to print
$hidden_forum = '
<form id="alt_forum_login" action="./forum/ucp.php?mode=login" method="post" style="display:none;">
<input type="text" name="username" id="username" value="'.strtolower($siteid).'" title="Username" />
<input type="password" name="password" id="password" value="'.$sitepw.'" title="Password" />
</form>';
PHP and link to submit form
<?php print $hidden_forum; ?>
<pre>Forum</pre>
I have what should be a relatively simple form in Rails that I'm using to send an email for two different previews, a desktop preview and a mobile preview.
<form id="email-form" role="form" action="<%= action_name == 'desktop_preview' ? email_preview_newsletter_path(#newsletter) : email_preview_newsletter_path(#newsletter, mobile: 'true') %>">
<label for="email_address">Email</label>
<input type="email" id="email_address" name="email_address" value="<%= params[:email_address] %>" placeholder="PLEASE ENTER EMAIL">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<input type="submit" value="Send" class="btn btn-primary"></input>
</form>
Right now I have it setup so that both previews get sent to the same endpoint, '/email_preview', but in the case of the mobile_preview I want to pass in a 'mobile' query string so that it ends up looking like this:
'/email_preview?mobile=true'
When I inspect the form on the page everything looks in order, however when it gets passed to the controller the 'mobile' part of the query string disappears and only the 'email_address' exists.
I suppose I could pass in the mobile value as a hidden field, but something about that just doesn't feel right to me. What is the best way to setup this form so that both the 'mobile' and 'email_address' key value pairs are passed as query strings when sent to the controller?
In the process of writing out this question I realized exactly what the problem was:
I had the form setup as a GET request as opposed to a POST request.
This was causing any pre-established query strings to get erased in the process of setting up the GET params being defined in the form (in this case, the 'email_address' param). Changing the form from GET to POST, (i.e. form method="POST")
Took care of this issue. Please note that if you are going to manually setup a form like this in rails then you also need to explicitly take care of the csrf token. This can be done by inserting the following input with the helper method into your form:
input type="hidden" name="authenticity_token" value="<%=form_authenticity_token%>"
Asp.net Mvc3 ads some custom attributes like "data-val-required" on input elements to perform validation. I know all theory behind this, how it works.
What i want to know is :
When I create my form inside " #using (Html.BeginForm())" it produces custom attributes, but it doesn't create those attributes when i place my form between plain "<form>" tag.
below is a demo i have created to demonstrate what iam saying
Razor Code, form inside BefingForm()
#using (Html.BeginForm()) {
#Html.EditorFor(model => model.EmailAddress)
#Html.ValidationMessageFor(model => model.EmailAddress)
}
generated Html contains "data-val-required" as attribute shown below
<input type="text" value="" data-val-required="The Email Address field is required." data-val-email="my message">
Razor Code Form inside pure Html Tag
<form action="/Account/Register" method="post">
#Html.EditorFor(model => model.EmailAddress)
#Html.ValidationMessageFor(model => model.EmailAddress)
</form>
generated Html doesnt contain "data-val-required" attribute shown below
<input type="text" value="" gtbfieldid="44">
My question is how can i ask MVC to add those attributes even form is placed in side pure html tags
I believe BeginForm method internally assigns a formcontext object to viewCotnext's property FormContext. If you do not want to use plain html form tags you have to do it manually like
<%
this.ViewContext.FormContext = new FormContext();
%>
and in razor it would probably be
#{
this.ViewContext.FormContext = new FormContext();
}
Problem here is that internally Html.BeginForm is flagged by Html.EnableClientValidation() to create FormContext that will store client-side validation metadata. Now, any HTML helper method that renders validation message also registers appropriate client-side validation metadata in FormContext. The result is what you get if you use helper. However, if you try to use HTML syntax and not helpers, the FormContext is never registered and therefore your validation is never added.
Regards,
Huske
After the user has logged in and their username authenticated and saved in session[:user_name], when submitting a form with method="post" (using standard html) all session data is cleared and user is routed back to the login page. This does not happen if the method is set to get.
Post works when I use the rails "form_tag" which generates these additional lines:
<div style="margin: 0pt; padding: 0pt; display: inline;">
<input type="hidden" value="✓" name="utf8">
<input type="hidden" value="a_bunch_of_gibberish" name="authenticity_token">
</div>
What is happening?
Are you using Rails 3.0.4? It sounds like it might be related to the CSRF fix.
If you need a fix specific to your needs, you can overwrite #handle_unverified_request in your controller. See https://github.com/rails/rails/blob/master/actionpack/lib/action_controller/metal/request_forgery_protection.rb.
Here's an example where this issue was with OmniAuth and OpenId. (See section 'CSRF Protection In Rails 3.0.4')
This issue can also happen if you're creating your own html form.
If you're getting redirected without knowing why, it's because of "protect_from_forgery" in your ApplicationController
In order to allow your form to post, add the following code to it (or use form_tag, explanation below):
<form ... >
...
<%= hidden_field_tag "authenticity_token", form_authenticity_token %>
...
</form>
The reason the "form_tag" works is because form_tag generates the hidden field for you =)
I've been troubleshooting this error for 12 hours now, and I think I have this narrowed down to this.
If I supply a post method, whether its a json object or a string, IE will allow anything up to ~3926 characters. Nothing else, no matter what shape or size its in. This is so long as its being passed like so :
<form method="post" action="/generate_csv.csv?calc[][amount_paid]=0.0&calc[][date_awarded]=02%2F02%2F1981&calc[][date_paid]=12%2F31%2F1981&calc[][interest_rate]=12.0&calc[][principal]=1955.96&calc[][tf]=0.912328767123288&calc[][total_interest]=214.14&calc[][amount_paid]=0.0&calc[][date_awarded]=1%2F1%2F1982&calc[][date_paid]=12%2F31%2F1982&calc[][interest_rate]=12.0&calc[][principal]=1955.96&calc[][tf]=1.0&calc[][total_interest]=234.72&calc[][amount_paid]=0.0&calc[][date_awarded]=1%2F1%2F1983&calc[][date_paid]=12%2F31%2F1983&calc[][interest_rate]=12.0&calc[][principal]=1955.96&calc[][tf]=1.0&calc[][total_interest]=234.72&calc[][amount_paid]=0.0&calc[][date_awarded]=1%2F1%2F1984&calc[][date_paid]=12%2F31%2F1984&calc[][interest_rate]=12.0&calc[][principal]=1955.96&calc[][tf]=1.0027397260274&calc[][total_interest]=235.36&calc[][amount_paid]=0.0&calc[][date_awarded]=1%2F1%2F1985&calc[][date_paid]=12%2F31%2F1985&calc[][interest_rate]=12.0&calc[][principal]=1955.96&calc[][tf]=1.0&calc[][total_interest]=234.72&calc[][amount_paid]=0.0&calc[][date_awarded]=1%2F1%2F1986&calc[][date_paid]=12%2F31%2F1986&calc[][interest_rate]=9.5&calc[][principal]=1955.96&calc[][tf]=1.0&calc[][total_interest]=185.82&calc[][amount_paid]=0.0&calc[][date_awarded]=1%2F1%2F1987&calc[][date_paid]=12%2F31%2F1987&calc[][interest_rate]=7.5&calc[][principal]=1955.96&calc[][tf]=1.0&calc[][total_interest]=146.7&calc[][amount_paid]=0.0&calc[][date_awarded]=1%2F1%2F1988&calc[][date_paid]=12%2F31%2F1988&calc[][interest_rate]=6.0&calc[][principal]=1955.96&calc[][tf]=1.0027397260274&calc[][total_interest]=117.68&calc[][amount_paid]=0.0&calc[][date_awarded]=1%2F1%2F1989&calc[][date_paid]=12%2F31%2F1989&calc[][interest_rate]=7.0&calc[][principal]=1955.96&calc[][tf]=1.0&calc[][total_interest]=136.92&calc[][amount_paid]=0.0&calc[][date_awarded]=1%2F1%2F1990&calc[][date_paid]=12%2F31%2F1990&calc[][interest_rate]=8.0&calc[][principal]=1955.96&calc[][tf]=1.0&calc[][total_interest]=156.48&calc[][amount_paid]=0.0&calc[][date_awarded]=1%2F1%2F1991&calc[][date_paid]=12%2F31%2F1991&calc[][interest_rate]=8.5&calc[][principal]=1955.96&calc[][tf]=1.0&calc[][total_interest]=166.26&calc[][amount_paid]=0.0&calc[][date_awarded]=1%2F1%2F1992&calc[][date_paid]=12%2F31%2F1992&calc[][interest_rate]=7.5&calc[][principal]=1955.96&calc[][tf]=1.0027397260274&calc[][total_interest]=147.1&calc[][amount_paid]=0.0&calc[][date_awarded]=1%2F1%2F1993&calc[][date_paid]=12%2F31%2F1993&calc[][interest_rate]=5.5&calc[][principal]=1955.96&calc[][tf]=1.0&calc[][total_interest]=107.58&calc[][amount_paid]=0.0&calc[][date_awarded]=1%2F1%2F1994&calc[][date_paid]=12%2F31%2F1994&calc[][interest_rate]=3.5&calc[][principal]=1955.96&calc[][tf]=1.0&calc[][total_interest]=68.46&calc[][amount_paid]=0.0&calc[][date_awarded]=1%2F1%2F1995&calc[][date_paid]=12%2F31%2F1995&calc[][interest_rate]=3.5&calc[][principal]=1955.96&calc[][tf]=1.0&calc[][total_interest]=68.46&calc[][amount_paid]=0.0&calc[][date_awarded]=1%2F1%2F1996&calc[][date_paid]=12%2F31%2F1996&calc[][interest_rate]=5.5&calc[][principal]=1955.96&calc[][tf]=1.0027397260274&calc[][total_interest]=107.87&calc[][amount_paid]=0.0&calc[][date_awarded]=1%2F1%2F1997&calc[][date_paid]=12%2F31%2F1997&calc[][interest_rate]=5.5&calc[][principal]=1955.96&calc[][tf]=1.0&calc[][total_interest]=107.58&calc[][amount_paid]=0.0&calc[][date_awarded]=1%2F1%2F1998&calc[][date_paid]=12%2F31%2F1998&calc[][interest_rate]=5.5&calc[][principal]=1955.96&calc[][tf]=1.0&calc[][total_interest]=107.58&calc[][amount_paid]=0.0&calc[][date_awarded]=1%2F1%2F1999&calc[][date_paid]=12%2F31%2F1999&calc[][interest_rate]=5.5&calc[][principal]=1955.96&calc[][tf]=1.0&calc[][total_interest]=107.58&calc[][amount_paid]=0.0&calc[][date_awarded]=1%2F1%2F2000&calc[][date_paid]=12%2F31%2F2000&calc[][interest_rate]=5.0&calc[][principal]=1955.96&calc[][tf]=1.0027397260274&calc[][total_interest]=98.07&calc[][amount_paid]=0.0&calc[][date_awarded]=1%2F1%2F2001&calc[][date_paid]=12%2F31%2F2001&calc[][interest_rate]=5.5&calc[][principal]=1955.96&calc[][tf]=1.0&calc[][total_interest]=107.58&calc[][amount_paid]=0.0&calc[][date_awarded]=1%2F1%2F2002&calc[][date_paid]=12%2F31%2F2002&calc[][interest_rate]=6.0&calc[][principal]=1955.96&calc[][tf]=1.0&calc[][total_interest]=117.36&calc[][amount_paid]=0.0&calc[][date_awarded]=1%2F1%2F2003&calc[][date_paid]=12%2F31%2F2003&calc[][interest_rate]=3.0&calc[][principal]=1955.96&calc[][tf]=1.0&calc[][total_interest]=58.68&calc[][amount_paid]=0.0&calc[][date_awarded]=1%2F1%2F2004&calc[][date_paid]=12%2F31%2F2004&calc[][interest_rate]=2.0&calc[][principal]=1955.96&calc[][tf]=1.0027397260274&calc[][total_interest]=39.23&calc[][amount_paid]=0.0&calc[][date_awarded]=1%2F1%2F2005&calc[][date_paid]=12%2F31%2F2005&calc[][interest_rate]=1.0&calc[][principal]=1955.96&calc[][tf]=1.0&calc[][total_interest]=19.56&calc[][amount_paid]=0.0&calc[][date_awarded]=1%2F1%2F2006&calc[][date_paid]=12%2F31%2F2006&calc[][interest_rate]=2.0&calc[][principal]=1955.96&calc[][tf]=1.0&calc[][total_interest]=39.12&calc[][amount_paid]=0.0&calc[][date_awarded]=1%2F1%2F2007&calc[][date_paid]=12%2F31%2F2007&calc[][interest_rate]=4.0&calc[][principal]=1955.96&calc[][tf]=1.0&calc[][total_interest]=78.24&calc[][amount_paid]=0.0&calc[][date_awarded]=1%2F1%2F2008&calc[][date_paid]=12%2F31%2F2008&calc[][interest_rate]=5.5&calc[][principal]=1955.96&calc[][tf]=1.0027397260274&calc[][total_interest]=107.87&calc[][amount_paid]=0.0&calc[][date_awarded]=1%2F1%2F2009&calc[][date_paid]=12%2F31%2F2009&calc[][interest_rate]=4.0&calc[][principal]=1955.96&calc[][tf]=1.0&calc[][total_interest]=78.24&calc[][amount_paid]=0.0&calc[][date_awarded]=1%2F1%2F2010&calc[][date_paid]=12%2F31%2F2010&calc[][interest_rate]=1.5&calc[][principal]=1955.96&calc[][tf]=1.0&calc[][total_interest]=29.34&calc[][amount_paid]=0.0&calc[][date_awarded]=1%2F1%2F2011&calc[][date_paid]=02%2F09%2F2011&calc[][interest_rate]=0.5&calc[][principal]=1955.96&calc[][tf]=0.10958904109589&calc[][total_interest]=1.07" accept-charset="UTF-8"><div style="margin: 0pt; padding: 0pt; display: inline;"><input type="hidden" value="✓" name="utf8"><input type="hidden" value="dbxrVZT2J42AB0QdMFi2XPggVGAQKtm8IkcuIj+U2jU=" name="authenticity_token"></div>
In all other browsers, this passes with no problem at all. But IE will not tolerate this past a certain point.
Does anyone know how I can pass the same amount of data in a small and condensed way or even in an alternative means?
An alternative, I was thinking, could be passing an alias of the object so that the object itself is passed between controllers, but not through the views. This being done without ever saving the object to the database. Just thinking out loud here.
Open to any ideas. :D
My Haml:
= form_tag generate_csv_path(:calc => #calc.results, :total_interest => #calc.total_interest, :per_diem => #calc.per_diem, :docket_num => #calc.docket_num, :our_file_num => #calc.our_file_num) do
= submit_tag 'Print CSV', :id => "print_csv"
UPDATE
So I'm looping through all the items trying to break them up into smaller hidden fields and they're all coming out as hashes
- #calc.results.each do |k, v|
= hidden_field :calc_result, "#{k[:total_interest]}"
Produces:
"117.68"=>"",
"166.26"=>"",
"147.1"=>"",
"107.58"=>"",
"58.68"=>"",
So unbelievable strange.. I thought I might be able to create a value as a hash eventually. So that 1 calc_result could ahve 5 different attributes in it.
Post the data as < form > body, not as part of the URL.
URLs have length-limit. Data POSTed as form body have no limit as such, since they are part of the header (not URL)
http://support.microsoft.com/kb/208427
UPDATE (in response to your comment)
Data as part of form body...
<form method="post" action="/generate_csv.csv">
<input type="hidden" name="calc[][amount_paid]" value="0.0"/>
... //other fields here
</form>