how to pass values from a jquerymobile page to a .m file - iphone

I have a series of form pages in my iphone app.
When the user completes the form and submits it the code needs to collate the form data and embed it into a predefined string.
Once the string has been created using the form values, i need to then pass that string so that it can be read by a .m file, for processing.
Can anyone please advise how i go about this ??
Please note I am a newbie to iphone app development

Simply post your form using an hidden field that contains your string
or use changePage with data argument:
$.mobile.changePage( "../resources/results.php", {
type: "post",
data: $( "form#yourId" ).serialize(),
changeHash: false
});

Related

Yii2 remove empty fields from url string

I need your help. I have an Active Form in my Yii2 application and when I submit my form it shows values (no matter empty or not) of every field of the form to the GET-string so it looks like
domain.com/index?ItemSearch%5Brooms_arr%5D=&ItemSearch%5Bprice_type%5D=& ItemSearch%5Bprice_type%5D=0&ItemSearch%5Barea_from%5D=&ItemSearch%5Barea_to%5D=&... etc.
I need to have cleaner query string which will contain only non-empty params?
For example domain.com/index?rooms_arr=12&price_type=normal.
Please suggest me what is the best way to do this?
This is not the yii2 problem. It is a native html form works like this. If you really do want to exclude all not filled inputs from the query string you could filter all this params via jQuery and set them to disable state, here is the code
$('form').submit(function(e){
var emptyinputs = $(this).find('input').filter(function(){
return !$.trim(this.value).length; // get all empty fields
}).prop('disabled',true);
});

C# - Get textbox value and send to a javascript function

I have a simple form with three textboxes and a <canvas> on the same page and I have to validate these three fields and then get the values (if validated) sent to a javascript function to draw a picture and some text inside the <canvas> element. The form and textboxes wouldn't have to disappear after the values were submitted because the user could try out different results with different values. I've done other forms before but never tried using Ajax. I know I could use a client-side validation and get the textbox values with jQuery but I have more server-side code running that would make use of these three values. How can I do this?
in your controller, create a method to handle the results. I assume that this is for logging only, and does not need to actually return data.
public useResults(string value1, string value2)
{
// ... Do something with the results
return Json(true);
}
In your view, work out a way to construct the url to the above action. Perhaps in a hidden field;
#Html.Hidden("useResultsUrl", Url.Action("useResults", "controllerName"))
Then in your javascript, attach a click event to the button, as you probably have already (to trigger your javascript task) and add in an ajax call.
Note that the following uses JQuery, but you could use microsoft AJAX if you preferred;
$(function () {
$("#button").click(function() {
$.ajax({
url: $("input[name='useResultsUrl']").val(), // Get the url from the hidden field
type: "POST",
dataType: "JSON",
data: $("input[type='text']").serialize() // Get the value of the text inputs and serialise them.
});
});
// ... do other stuff
});
Your View can make an ajax call to the server using JQuery - either using JQuery.post
or JQuery.ajax - you give the Url of the controller action to the JQuery method, and it will handle the AJAX call for you.
Then, in your controller action, you return a JsonResult - which serialize the data for you into JSON format:
e.g. return Json( model );
Finally, implement a success function in the JQuery Ajax call in your view - this wil have the data returned by the controller available for you to do whatever you want with.

Is it possible to pass post data to the form (prefill form with data)?

For example https://stackoverflow.com/questions/ask there we have form id="post-form" which has method="post", is it possible somehow open this form and have lets say Name input (display-name) with my name prefilled on load?
Yes. You can do this many ways, with Javascript by setting the input's text, or you can do it server-side with PHP by echoing "value=\"$name\"" for the value attribute of the input.

Accessing form variables in a dynamic dijit.dialog (content of which is from href)

I have the following code to create a dijit.diagram which loads a form from an external link:
function openDialog(userID)
{
composeDialog = new dijit.Dialog({
id: 'composeDialog',
title: 'Compose a Message',
style: 'width: 400px',
href: 'myform.php?userID='+userID
});
composeDialog.show();
}
Now inside my href I have a form that asks the user for several pieces of information, but I am unable to access any of the values. Also if the form is actually submitted, then the user is re-directed to the proper page but none of the variables are passed along. When I try to access my form with dijit.byId('myform') all I get is a null object. Does anybody have any idea?
Thank you very much!
Javascript is not executed in dijit.Dialog. Use dojox.widget.DialogSimple instead. See this reference
Then, pass the values of the form from the dialog to the page using javascript.

passing text from an Array to UIWebView

i want to pass some html i have saved as string and stored in an array into a UIWebView.
can anyone help me on how to do this because all i can find is how to grab it from the internet rather than already stored data
Thanks
Are you trying to provide generated HTML content to a UIWebView? If so, you'll want to use -[UIWebView loadHTMLString:baseURL:]. You can pass your HTML string for the first argument, and nil in for the second argument.