Passing a Cookie Value Through Form To PHP - javascript

I made this post to try to see if there is a different way (or something I'm doing wrong) to get my Cookie with an value into a hidden input which can send the value through a form to my MySQL database.
I am trying to grab a cookie with my "getCookie()" function and then put it in a hidden form to then pass through to my database. There may be simpler ways I am unaware of, but currently this is what I have:
Inside my form I have:
var cookie_val = getCookie("id"); and
$('input[name=id]').val(cookie_val);
When outputting the "getCookie("user")" simply with a document write I get the value that I am looking for, however, in my MySQL database when it arrives it ends up as a value of 0. I am not fully understanding of how
$('input[name=id]').val(cookie_val);
works.
I am fairly confident that my PHP code is not the issue in all of this.

Related

Post Array using window.location.href in ASP.NET MVC

I need to send data to a Controller to Post data currently I'm not using a form only I need to send an array for parameters, what is the right way to do it ?now I'm using this line of code but I know that it is used for Get method instead of Post method:
window.location.href = "#Url.Action("Edit", "PurchaseOrder")?arr"+urlParams;
the only easy way to post data to a controller is to do it through a form. but that doesnt mean the form needs any text input or stuff like that as long as code the data in and you make it invisible for a user you can just use a button that looks like a normal button but is actually a form in de code.
else if you dont want to use a form to send the data even if the inputs on the form are not visible you could use AJAX to send a post request but i dont think you want to do that.
if you are already getting the data from a different page in my oppinion it would be easier to just use sessions to store the values when you get them for the first time

Store values submitted in url

I have a page which is coded like this. http://localhost/test/index.html?Job=123456&Customer=11111&Number=32333
What i want to do is read this form data when the page is input, as i need to add Job and Customer to the html form i have which is using method="post" and using action="phppage.php" to post this data along with an array to phppage.php, which is then using $_GET["Job"]. I have tried various javascript functions from these pages, but just seem to be missing the values. I have confirmed the data will post by using <input type="hidden" value="12345" name="Customer" id="customer"> hard coded and this is being brought through. What i need to do is set value for both required fields. Appreciate any help with the javascript function i need.
First of all, it is not secure to pass value in url like this, if you are using javascript, you have to use encodeURIComponent to encode your url.
and second, you can get the passed parameters from url using these codes:
var decodedUrl = decodeURIComponent(window.location);
var Parameters = decodedUrl.split("&");
First thing the link you have added here wont work since its in your local machine(which means it will be accessible only in your pc).
Second if your form is using post method for sending data to the page you cant get it with $_GET['somename']. you should use $_POST['somename']
since i cant see your code i would
create the form reading this tutorial http://www.w3schools.com/html/html_forms.asp
then create the php reading this https://www.tutorialspoint.com/php/php_get_post.htm
also note that your url shows that your page is using get method to send data to the page

How do you call a Django view with parameters from JavaScript?

I'm looking to capture and save the state of a page (Django template + backend) after the user makes some modifications (through JQuery) to the appearance of the page. Now that I've gotten hold of the innerHTML using a JS variable, I need to send it over to the Django view that will do the saving. How do I call this Django view and pass it the JS variable?
P.S: First ever question on stackoverflow, please let me know if the question isn't clear or is improperly formatted.
Handiest way to get started is to first make a proper form and a django view that reacts to it ("request.post"). The form should have fields for whatever you're changing in the page.
Next up, submit that form's variables from your page with jquery.ajax.
So the idea is to isolate the various problems:
What should be the form parameters?
Get a view running that makes the actual changes.
Get the javascript working.

JavaScript: How to read browser's cache of POST data?

Effort
I've read this question, but I still think there has to be a way to do this client side.
Case
I'm submitting a form that has a few inputs. When the form is submitted, the primary key of those inputs is shown on a results page along w/ other data and a different form.
The effect I'm trying to do is if the input-pk is modified, I want it to reload the page (think window.location.reload()), only I want to update that PK parameter's value with the changed value.
window.location.reload takes one of two values (true/false), which distinguishes if it should use browser cache or not. Thus, it seems like it should be accessible, especially since the Firebug::Net plugin shows the param in the HTTP Header.
The form requires 'Post' submissions, which adds a little more complexity.
Alternative
The other thing I've considered is to store the values in a cookie right before submission, which I can retrieve on the next page and then submit another Post; however I'd like to refrain from exposing the data in Cookies.
AFAIK, Javascript does not have access to the POST body. Can't think of an API call for that! If you are using php/.net/ruby, you can encode the POST body as JSON that your JS can use when it's reloaded, can't you?

How to get value of hiddenfield in another form

iIhave value in hdnField in form1.aspx . I assign a value to hdnfield in javascript .I want to get that value in aspx.vb in another form, form2.aspx. How can I accomplish this?
If your Form1.aspx submits to Form2.aspx, then you have atleast a few ways to access the value of form fields (including Hidden fields):
The Request.Form property exposes a NameValueCollection containing all submitted form field names as Keys and their values as Values. You could use the syntax Request.Form["fieldName"] to access the value.
If this is ASP.NET 2+ and you used the Cross-page posting technique, you will be able to access field values in the previous page using the PreviousPage property of the Page.
If you use Server.Transfer, you can access values using the Current HttpContext.
If you need more info, you should take a look at Passing values between pages in ASP.NET.
I think your concept of session is wrong. Session is a server-side object, and javascript runs on the client, so you can not directly assign that value to a session. You can, instead, use some AJAX to send it to the server and then add code in the server so the value is assigned.
Hm... you have to think about the difference between serverside and clientside first...
You cant directly access changes you made in the client on the serverside, because you once send a request to server, as a response you get the site diplayed in your browser. As soon as you recieve the request, the server is finished and cant access the site anymore. Its like a letter you send away. As soon as you put it into the mailbox, you cant make changes anymore.
But you could post a new request to the server and add POST or GET peremeters. These can be accessed by the server. The way you send the request doesnt matter... you can send a request using AJAX or simply reload the page.

Categories

Resources