Hallo! I want to send variable few times(each time with different value) in one post query.
In HTML form it works and looks like:
<form method="POST" action="http://localhost/index.php">
<input type="hidden" name="line_item" value="value1">
<input type="hidden" name="line_item" value="value2">
<input type="hidden" name="line_item" value="value3">
</form>
But appcelerator sends only the last value in this code:
var httpClient = Titanium.Network.createHTTPClient();
var params = {
line_item:'value1',
line_item:'value2',
line_item:'value3',
};
httpClient.open('POST', 'http://localhost/index.php');
httpClient.send(params);
Can anyone help? Thanks.
Sorry, I forgot to mention that I don't have access to server and I need it solved in appcelerator.
if you use PHP as server platform, you can join POST-variables to array
<form method="POST" action="http://localhost/index.php">
<input type="hidden" name="line_item[]" value="value1">
<input type="hidden" name="line_item[]" value="value2">
<input type="hidden" name="line_item[]" value="value3">
</form>
and then process it like array in php:
if (is_array($_POST['line_item[]'])) {
$count = 0;
foreach($_POST['line_item[]'] as $line_item)
echo($line_item . " #" . $count++);
}
Solved...
var httpClient = Titanium.Network.createHTTPClient();
httpClient.open('POST', 'http://localhost/index.php');
httpClient.send("line_item=value1&line_item=value2&line_item=value3");
Related
I'm searching the answer but without any luck. Perhaps I asked wrong question. I have a form in my cms page in PS 1.6. Code below:
<form method="post" action=""><input name="text1" type="text" /><br /> <input value="Check" onclick="getStatus()" type="button" /></form>
In \override\controllers\front\CmsController.php I have getStatus function. Which return "Hello world". Like You see "action" in form is empty. How to create link to this controller which is overrider ?
Kind regards
you can do like this.
In tpl
<form method="post" action="">
<input name="text1" type="text" /><br />
<input type="hidden" name="action" value="getStatus">
<input value="Check" type="submit" />
</form>
In Override controller
class CmsController extends CmsControllerCore
{
public function initContent(){
parent::initContent();
if(Tools::getValue('action') && Tools::getValue('action')=='getStatus'){
// Do your work What you want
echo "Hello world";
}
}
}
You can put: _PS_URI_?controller=cms&id_cms=1
Also can check dispatcher core and add your own rule or create a little module.
If is an override Controller u delete the file cache/class_index.php ?
I am trying to create a form whereby I can select multiple files (they will be pdfs) and insert the file and the file's name into the database.
Html form works beautifully:
<form action="" method="POST" enctype="multipart/form-data">
<input type="file" name="files[]" multiple/>
<input type="submit"/>
</form>
But I can't seem to make the php work with it:
if(isset($_POST['files[]'])){
$file_name = $_POST['files[]']['name'];
$file_size =$_POST['files[]']['size'];
$file_type=$_POST['files[]']['type'];}
$query="INSERT INTO upload_data (`FILE_NAME`,`FILE_SIZE`,`FILE_TYPE`) VALUES('$file_name','$file_size','$file_type'); ";
I also don't know how to insert the actual file, as opposed to just its properties. Any ideas?
UPDATE:
I got how to upload multiple files, and also multiple file names, but I cannot do both at the same time. Still need help. The code is:
<form action="" method="POST" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="30000" />
<input type="file" name="files[]" multiple/>
<input type="submit"/>
</form>
if(isset($_FILES['files'])){
foreach ($_FILES['files']['name'] as $filename) {
$query=mysql_query("INSERT INTO practice (name) VALUES('$filename')", $c) or die("six");
}
}
and
if(isset($_FILES['files'])){
foreach ($_FILES['files'] as $file) {
$query=mysql_query("INSERT INTO practice (file) VALUES('$file')", $c) or die("six");
}
}
To get information about uploaded files, you need to use the $_FILES variable instead of the $_POST variable : http://www.php.net/manual/en/features.file-upload.post-method.php
I need to open some URL in WebView from the source code of an another URL. I am getting source code of that URL via ScriptNotify event. That URL contains a <form /> with GET/POST request & parameters
The HTML can contain either this
<form id="pay" method="GET" target="_blank" action="https://xxxxx.com/qqq/www">
<input type="hidden" value="643" name="param1">
<input type="hidden" value="313.62" name="param2">
<input type="hidden" value="GZc6PFXOTfmY58yJyk3DTg==" name="param3">
</form>
Or this
<form id="pay" method="POST" target="_blank" action="https://xxxxx.com/qqq/www">
<input type="hidden" value="643" name="param1">
<input type="hidden" value="313.62" name="param2">
<input type="hidden" value="GZc6PFXOTfmY58yJyk3DTg==" name="param3">
</form>
Now if I have GET method then I can develop URL by parsing the source code, it will become this for our example. I can open in WebView
https://xxxxx.com/qqq/www/?param1=643¶m2=313.62¶m3=GZc6PFXOTfmY58yJyk3DTg==
How can I do same if there's POST request ?
There's no method on WebView allowing you to perform a POST request. You could do it by invoking a JavaScript function inside WebView, though. First you need to construct a web page containg the form you require and a JavaScript function submitting it:
var html =
#"<html>
<head>
<script type=""text/javascript"">
function Submit()
{
document.getElementById('pay').submit();
}
</script>
</head>
<body>
<form id=""pay"" method=""POST"" action=""https://xxxxx.com/qqq/www"">
<input type=""hidden"" value=""643"" name=""param1"">
<input type=""hidden"" value=""313.62"" name=""param2"">
<input type=""hidden"" value=""GZc6PFXOTfmY58yJyk3DTg=="" name=""param3"">
</form>
</body>
</html>";
You then navigate to this HTML string and invoke the function:
webView.NavigateToString(html);
webView.InvokeScript("Submit", null);
During tests the second call always executed before the page was actually loaded and failed because of that so I had to work around it by reacting to LoadCompleted event:
webView.LoadCompleted += WebViewOnLoadCompleted;
webView.NavigateToString(html);
private void WebViewOnLoadCompleted(object sender, NavigationEventArgs navigationEventArgs)
{
webView.LoadCompleted -= WebViewOnLoadCompleted;
webView.InvokeScript("Submit", null);
}
Well i have this search engine into my site
<form action="/apps/search/" name="g_search" id="cse-search-box" method="post">
<input type="hidden" name="cof" value="FORID:11;NB:1" />
<input type="hidden" name="ie" value="utf-8" />
<input type="text" autocomplete="off" name="google_seach" class="search-text" onfocus="searchtext('focus')" onblur="searchtext('blur')" />
<label style="color:#796b6b;float:left;padding:0;">|</label>
<input type="submit" style="float:right;margin-top:3px;cursor:pointer;width:16px;height:16px;background:url(/template/img/main/search-icon.jpg);border:none;" value="" alt="Αναζήτηση" title="Αναζήτηση" />
</form>
Now i want some code to results page.Somehow the post request readed from a file called search.php
This file have access to $_POST[] array..
The file initializes $selector variable (for template use).
What we want to echo into contentarea div must put into $body variable..
Any help?
<?php
$selector="search";
$body="<div id=\"cse-search-form\" style=\"width: 100%;\">Loading</div>";
?>
I have a similar issue, just use GCS code provide by Google as it easy, make sure in the option in GSE you select to visualize the search result on your page and not an Iframe
with a form am searching schools nearby and displaying them as table.
inside views.py
def method1:
printquery = request.POST.copy()
zip = printquery['zip']
if not zip:
city = printquery['city']
state = printquery['state']
zip = getZip(city,state)
results = zipObj.getSchools(zip);
render_to_response('some.html',{'results':results,'query':printquery,})
inside template
<form id="print-search" target="_blank" action="" method="post" name="print">
<input type="hidden" value="{%if query%}{{query}}{%endif%} name="query"/>
<input type ="submit" value="Print the Results" name="submitPrint"/>
</form>
<table>
{% block xxx%}displays schools result {%endblock%}
</table>
when the "Print the results" button is clicked.I want to use 'query',
do the search again and print in separate page[I have no choice of storing in session id].
Problem am facing is, {{query}} is a turing to a string i.e.,u"{'zip': u'76123'"} on which i cannot do something like query['zip'],
Is there a way to solve this. Ideas are most welcome.
Instead of taking the whole dictionary as value, do something like this
<form id="print-search" target="_blank" action="" method="post" name="providerprint">
<input type="hidden" value="{%if query.zip %}{{query.zip}}{%else%}""{%endif%}" name="zip"/>
<input type="hidden" value="{%if query.city %}{{query.ciyt}}{%else%}""{%endif%}" name="city"/>
<input type="hidden" value="{%if query.state %}{{query.state}}{%else%}""{%endif%}" name="state"/>
<input type ="submit" value="Print this Search" name="submitProviderprint"/>
</form>
inside the views.py we can access this as
zip = params['zip']
city = params['city']
state = params['state']
and it worked for me.:)