Sinatra creating a delete http request using name="_method". What is going on? - sinatra

I read this:
http://guides.rubyonrails.org/form_helpers.html#how-do-forms-with-patch-put-or-delete-methods-work-questionmark
and I still have the question of how this html form is working behind the scenes.
<form action='/<%= idea.id %>' method='POST'>
<input type="hidden" name="_method" value="DELETE">
<input type='submit' value="delete"/>
</form>
Is Sinatra looking specifically at the <input> name field and does that _method mean something internally to Sinatra and Rails? If so, what is going on behind the scenes?

Yes - as documented in the Sinatra Readme :
Use _method magic to allow put/delete forms in browsers that don't support it.
The "magic" is actually implemented in the Rack middleware, see the code in 'lib/rack/methodoverride.rb'

Related

Creating a case from Microsoft Forms into Salesforce

Is there a way to take responses filled in Microsoft Forms and create a case into Salesforce?
I have not gathered enough information to attempt this problem.
I can answer from SF side, you'll have to translate to MS world.
Salesforce offers somewhat dated but simple feature called web-to-case (and there's even email-to-case if for some bizarre reason it'd be easier for you). Your SF admin can enable it, decide which case fields they want to capture and SF generates 2 things:
starts to accept the cases created this way
generates sample html form for you
That form will be stupid. Like braindead stupid. No javascript (well, you can put recaptcha on it), minimal styling, just a bunch of fields and <form> that does POST to certain url. It'll show <select>s and stuff (of course if you add new picklist values or new records to a field that's actually a lookup on the case - you should regenerate the html, there's no magic). It's good for quick & dirty injecting into other page's code and calling it a day.
<form action="https://webto.salesforce.com/servlet/servlet.WebToCase?encoding=UTF-8" method="POST">
<input type=hidden name="orgid" value="00D...redacted">
<input type=hidden name="retURL" value="http://example.com">
<label for="name">Contact Name</label><input id="name" maxlength="80" name="name" size="20" type="text" /><br>
<label for="email">Email</label><input id="email" maxlength="80" name="email" size="20" type="text" /><br>
<label for="phone">Phone</label><input id="phone" maxlength="40" name="phone" size="20" type="text" /><br>
<label for="subject">Subject</label><input id="subject" maxlength="80" name="subject" size="20" type="text" /><br>
<label for="description">Description</label><textarea name="description"></textarea><br>
<input type="hidden" id="external" name="external" value="1" /><br>
<input type="submit" name="submit">
</form>
A developer can reverse engineer a regular POST call out of that form.
And you should. As you can see I've redacted my org's ID. Spamer could use it to send you a lot of messages that way and exhaust your storage usage for example. So ideal solution would do your UI however you want, with captcha if needed, pass data to server, then your server side would make POST call to Salesforce, with org id being secret. (org id for production is very unlikely to change but if you use SF sandbox and later refresh it - it'll get new id, you'll need to update your integration)
It's bit naive but it works. If you need more (for example Case+attachments) you will have to put more leg work, make proper integration that logins to SF, maybe even runs some "describe" calls to dynamically fetch fields/picklist values/lookup records to generate the form. What's your poison, SOAP (old but you'd "consume" the WSDL file and work with classes, objects in your language) or REST...
Check out my other answers (shameless plug)
How to include attachments when cases are submitted via web-to-case to web-to-lead scenarios?
Integrate salesforce and backendless (PHP but same idea)
Machform integration with Salesforce (again PHP and web-to-lead which is similar feature but there's some good philosophical ranting in it)

PHP 5.3.10 global behaviour

I'm having trouble with a global variable, I think it might be pulling its data from a HTML Form Input, but I can't find any documentation on the web about global var pulling data from a HTML Form Input.
Thanks.
When a form is submitted the method tag specifies if it is a POST or GET request. Depending on what method your form is using your form values can either be in your $_POST or $_GET Super global.
Example:
<form action="welcome.php" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>
After the submit button on the form is clicked the form contents can be found by referencing the name attribute in the super global(In this case the POST).
$_POST['name']
$_POST['email']
For documentation see
http://php.net/manual/en/reserved.variables.post.php
This applies to PHP 4 >= 4.1.0, PHP 5, PHP 7 ie. fits PHP 5.3.

Why does my form not upload files in Internet Explorer 9?

Welcome to episode 32,342,343 of "Why does Internet Explorer Suck So Much?"...
I've seen lots of reports that IE9 does a crappy job uploading files. Apparently it has lots of caveats about when it will or won't work (If someone has a definitive list I'd love to see it). However, most of the problems/solutions I see have found are related to javascript, usually the jQuery form plugin or something similar.
My form is not submitted via AJAX and the the file input field is not hidden or obscured with css. Yet, I get several support tickets per day from users on IE9 trying to submit the form and "nothing happens" (=the form submits. No errors, but the file is not uploaded.) I haven't gotten a single complaint with a different browser, and IE8 even seems to work (as well as it ever does).
Here's the top of my form. Am I missing something?
<form action="http://mysite.dev/account-settings/?open=resume" method="post" class="wpjb-form" enctype="multipart/form-data">
<input type="hidden" name="resume_form" value="resume_form" />
<fieldset class="wpjb-fieldset-default">
<input id="firstname" name="firstname" type="hidden" class="regular-text " value="John" />
<input id="lastname" name="lastname" type="hidden" class="regular-text " value="Henry" />
<input id="email" name="email" type="hidden" class="regular-text " value="john.henry#johnhenry.com" />
<div class="wpjb-element-input-checkbox wpjb-element-name-is_active">
<label class="wpjb-label">Show resume? </label>
<div class="wpjb-field">
<label for="is_active_1"><input type="checkbox" class="" name="is_active" id="is_active_1" value="1" checked="checked" /> Yes <small style="display:inline;">(Uncheck to hide your resume)</small></label>
</div>
</div>
<div class="wpjb-element-input-select-one wpjb-element-name-file">
<label class="wpjb-label">Upload a <i>new</i> resume file</label>
<div class="wpjb-field">
<input style="line-height:1em;" id="file" name="file" type="file" class="regular-text " />
<small class="wpjb-hint">Accepted file types: doc, docx, odf, pdf, rtf</small>
</div>
</div>
</fieldset>
...
It goes on like this with a couple more <fieldset>s then ends like this:
....
<p class="submit">
<input type="submit" name="Submit" id="wpjb_submit" value="Save Changes" />
</p>
</form>
Update
I'm happy for everyone who has never experienced this problem but it's not just me:
http://answers.microsoft.com/en-us/ie/forum/ie9-windows_vista/cannot-upload-files-using-internet-explorer-9/5724d921-ae71-e011-8dfc-68b599b31bf5
Update2
I'm seeing a lot of suggestions to add a meta tag to force the user agent to IE8...
<meta http-equiv="X-UA-Compatible" content="IE=8" />
I don't want to do this because although I do support IE8, many of the elements on my site render differently in IE8 vs. IE9. This would create a rather sloppy user experience as any IE users would experience I temporary "time warp" back to IE8 on that specific page.
I was able to fix this nightmare of a problem by wrapping a jQuery form submit in a setTimeout:
$('#complete_profile input[type="submit"]').click(function(){
setTimeout(function() {
$('#complete_profile form').submit();
}, 0);
});
This may cause duplicate submission when the form DOES submit, however, so be careful.
As Graham does, I think that this might more be a server issue - also I have never had issues with fileuploads in IE9 (or newer) - I guess you don't want to post the code of the PHP Script that handles the upload?
if any data is not being sent, You could check the post data by your hidden input on your server side script. For example if you're using php it would be something like
<? if($_POST['resume_form']=='resume_form'){
//Do something
} ?>
Or you could also use meta compatible tags for IE to render the page like IE8
<meta http-equiv="X-UA-Compatible" content="IE=8" />
I suggest setting the X-UA-Compatible meta tag value and seeing whether that makes any difference.
See this question for possible values: What does <meta http-equiv="X-UA-Compatible" content="IE=edge"> do?
It may also be that the page is triggering a non-standards mode in IE9. I suggest opening the page in IE9, opening the developer tools, and seeing which browser/document modes are selected. That may give you a clue. Note that the "enctype" form attribute was not supported prior to IE8, so if the browser is using an older doc mode, that attribute is not being recognized.
OK I'd rather leave a comment not an answer but I don't have the points for that yet!
Are the users in quirks mode? Most IE users are unaware of the quirks mode and may have accidentally clicked it when trying to refresh the page (instead of pressing F5). If it is intermittent this could be the reason why.
following on from above.. On the server side how are you checking for empty fields? I'm more on the lines of JS here where you often look for "", null and undefined I'm just thinking that perhaps the quirks mode is sending some fuzzy data that your server side error checking is missing because you aren't looking for it and hence reports all is OK.

Programmatic login into jsf application

I found examples of programmatic login into jsf based application, like this from Balusc.
Maybe it is silly question but, when I use form based authentication, I can use only a simple html form with
<input id="username" type="text" name="j_username" />
<input id="password" type="password" name="j_password"/>
in <form method="post" action="j_security_check"> form.
I cannot use jsf form from example, why?
Because it's not JSF who handles the login, it's the container itself. The JSF <h:form> does not allow you to specify a specific action URL. So you have to use <form>.
But your question title is confusing. Using a j_security_check form is not "programmatic login". It's "container managed login". The real programmatic login way is calling HttpServletRequest#login() yourself. You can do this in a JSF managed bean action method which is invoked by a JSF <h:form>.

POST request in GWT

i first tried to make request to server with GET method and it works fine. my request would process a file then return as a pdf file and would open on a new browser. what i did is overriding the doGet() method. since having a GET request is only limited to few parameters, i must change it to doPost() mehod but the problem is that it can't be overrided because the method is final.
in an HTML FORM, what i wanted to happen is something like this:
<form method="post" action="http://differentdomain.com/appserv/appserv.php">
<input type="hidden" name="fwi_script" value="app/custom/cusapp/interface" />
<input type="hidden" name="trx" value="<trx>
<productid>PROD1</productid>
....../** transaction details here */
</trx>" />
<input type="hidden" name="fcompanyid" value="SHOST101" />
<input type="hidden" name="fwi_action" value="PRINT_PENDING_SALES" />
<input type="hidden" name="fexcel" value="0" />
<input type="submit" value="Submit" />
</form>
this html form will print the order slip of every transaction when user clicks on the post order button.
anyone can give an idea on how to POST request in GWT server? i think i can't do it with RequestBuilder since i will be having the SOP problem since i will be connecting to a different domain.
To build very nearly the same html you have in your question, start with a FormPanel and add the form fields you need to it. Make sure to configure the FormPanel with the correct action and method, and to provide names (and possibly values) to the fields added to it. To fire off the request, submit() can be called.
The solution is to make a normal GWT RPC call to your server and have the server make the POST request to the server located on a different domain.