/// <summary>Called when the form is submitted through onsubmit="FormExampleHandler.OnSubmit".</summary>
	/// <param name="form">A simple object holding the values of all your form inputs by name.</param>
	public static void OnSubmit(FormData form){
		Debug.Log("Form submitted!");
		
		// Usage is simply form["fieldName"], or form.Checked("fieldName") for easily checking if a checkbox is ticked.
		// You can alternatively use e.g. UI.document.getElementById("aFieldsID").value and manage radio inputs manually.
		
		Debug.Log("handling a form with C#.");
		
		// Give a feedback message to show something's happened:
		UI.document.getElementById("csMessage").innerHTML="Please check the console!";
		
		// And simply log all the fields of the form:
		Debug.Log("Your name: "+form["yourName"]);
		Debug.Log("Awesome? "+form.Checked("awesome"));
		Debug.Log("Epic? "+form.Checked("epic"));
		Debug.Log("Pretty? "+form.Checked("purdy"));
		Debug.Log("Unique? "+form.Checked("unique"));
		Debug.Log("Wonderful? "+form.Checked("wonderful"));
		Debug.Log("Your dropdown selection: "+form["favourite"]);
		Debug.Log("Your Bio: "+form["myBio"]);
		
	}
Ejemplo n.º 2
0
        /// <summary>Submits this form.</summary>
        public void submit()
        {
            // Generate a nice dictionary of the form contents.

            // Step 1: find the unique names of the elements:
            Dictionary <string, string> uniqueValues = new Dictionary <string, string>();

            List <Element> allInputs = GetAllInputs();

            foreach (Element element in allInputs)
            {
                string type = element["type"];
                if (type == "submit" || type == "button")
                {
                    // Don't want buttons in here.
                    continue;
                }

                string name = element["name"];
                if (name == null)
                {
                    name = "";
                }

                // Step 2: For each one, get their value.
                // We might have a name repeated, in which case we check if they are radio boxes.

                if (uniqueValues.ContainsKey(name))
                {
                    // Ok the element is already added - we have two with the same name.
                    // If they are radio, then only overwrite value if the new addition is checked.
                    // Otherwise, overwrite - furthest down takes priority.
                    if (element.Tag == "input")
                    {
                        InputTag tag = (InputTag)(element.Handler);
                        if (tag.Type == InputType.Radio && !tag.Checked)
                        {
                            // Don't overwrite.
                            continue;
                        }
                    }
                }
                string value = element.value;
                if (value == null)
                {
                    value = "";
                }
                uniqueValues[name] = value;
            }

            FormData formData = new FormData(uniqueValues);

            // Hook up the form element:
            formData.form = Element;

            object result = Element.Run("onsubmit", formData);

            if (!string.IsNullOrEmpty(Action) && (result == null || !(bool)result))
            {
                // Post to Action.
                FilePath path = new FilePath(Action, Element.Document.basepath, false);

                FileProtocol fileProtocol = path.Handler;

                if (fileProtocol != null)
                {
                    fileProtocol.OnPostForm(formData, Element, path);
                }
            }
        }
		/// <summary>Submits the given form to the given path using this protocol.</summary>
		public virtual void OnPostForm(FormData form,Element formElement,FilePath path){}
Ejemplo n.º 4
0
		/// <summary>Submits this form.</summary>
		public void submit(){
			
			// Generate a nice dictionary of the form contents.
			
			// Step 1: find the unique names of the elements:
			Dictionary<string,string> uniqueValues=new Dictionary<string,string>();
			
			List<Element> allInputs=GetAllInputs();
			
			foreach(Element element in allInputs){
				string type=element["type"];
				if(type=="submit"||type=="button"){
					// Don't want buttons in here.
					continue;
				}
				
				string name=element["name"];
				if(name==null){
					name="";
				}
				
				// Step 2: For each one, get their value.
				// We might have a name repeated, in which case we check if they are radio boxes.
				
				if(uniqueValues.ContainsKey(name)){
					// Ok the element is already added - we have two with the same name.
					// If they are radio, then only overwrite value if the new addition is checked.
					// Otherwise, overwrite - furthest down takes priority.
					if(element.Tag=="input"){
						InputTag tag=(InputTag)(element.Handler);
						if(tag.Type==InputType.Radio&&!tag.Checked){
							// Don't overwrite.
							continue;
						}
					}
				}
				string value=element.value;
				if(value==null){
					value="";
				}
				uniqueValues[name]=value;
			}
			
			FormData formData=new FormData(uniqueValues);
			
			// Hook up the form element:
			formData.form=Element;
			
			object result=Element.Run("onsubmit",formData);
			
			if( !string.IsNullOrEmpty(Action) && (result==null||!(bool)result) ){
				// Post to Action.
				FilePath path=new FilePath(Action,Element.Document.basepath,false);
				
				FileProtocol fileProtocol=path.Handler;
				
				if(fileProtocol!=null){
					fileProtocol.OnPostForm(formData,Element,path);
				}
			}
		}
		public override void OnPostForm(FormData form,Element formElement,FilePath path){
			// Post to HTTP; Action is our URL.
			HttpRequest request=new HttpRequest(path.Url,OnFormSent);
			request.ExtraData=formElement;
			request.AttachForm(form.ToUnityForm());
			request.Send();
		}
 /// <summary>Submits the given form to the given path using this protocol.</summary>
 public virtual void OnPostForm(FormData form, Element formElement, FilePath path)
 {
 }