Getting response from python to browser (CGI python) - python-2.7

I am trying to get(reflect) corresponding radio button as soon as I choose the option from dropdown menu.
I am unable to get the answer, I am new to python. could you guys please help , below is my code :
HTML CODE:
<!DOCTYPE html>
<html>
<head>
<title>
Program
</title>
</head
<body>
<h3>
first program :)
</h3>
<form action="/cgi-bin/mds/dropdown.py" method="post">
<br>
<select name="dropdown" >
<option value="MCR" selected> MCR </option>
<option value="OCS" > OCS </option>
</select>
<input type="radio" name="file" value="raw"> raw <br />
<input type="radio" name="file" value="std" /> std <br/>
<input type="submit" value="Submit" />
</form>
</body>
</html>
My expectation when I select any of the OCS/MCR dropdown, the radio button should dynamically generate with raw/std name.
dropdown.py file code:
#!/usr/bin/python
import cgi
import cgitb
form = cgi.FieldStorage()
if form.getvalue('dropdown'):
menu = form.getvalue('dropdown')
else :
menu = "not entered"
print("Content-type:text/html\r\n\r\n")
print("<html>")
print("<head>")
print("<title>Hello - Second CGI Program</title>")
print("</head>")
print("<body>")
print("<h2> %s </h2>" % (menu))
print("</body>")
print("</html>")

If i well understand you need to do that using ajax (jquery) in your html file, it sends request asynchronously to your python file that handles it as what you clicked on.
maybe this link helps you
jQuery get value of select onChange

Related

Django and Salesforce Web to Lead

We have website developers redesigning the whole site in Django, and these are questions from our website developers I don't have any real knowledge of how to answer, so I thought someone here might be able to help.
We ran into a few problems with the web to lead and having it map to Salesforce which I HOPE we resolved.
Here's the code snippet:
<!-- ---------------------------------------------------------------------- -->
<!-- NOTE: Please add the following <META> element to your page <HEAD>. -->
<!-- If necessary, please modify the charset parameter to specify the -->
<!-- character set of your HTML page. -->
<!-- ---------------------------------------------------------------------- -->
<META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=UTF-8">
<!-- ---------------------------------------------------------------------- -->
<!-- NOTE: Please add the following <FORM> element to your page. -->
<!-- ---------------------------------------------------------------------- -->
<form action="https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8" method="POST">
<input type=hidden name="oid" value="SFDCidhere">
<input type=hidden name="retURL" value="http://">
<!-- ---------------------------------------------------------------------- -->
<!-- NOTE: These fields are optional debugging elements. Please uncomment -->
<!-- these lines if you wish to test in debug mode. -->
<!-- <input type="hidden" name="debug" value=1> -->
<!-- <input type="hidden" name="debugEmail" -->
<!-- value="emailaddresshere"> -->
<!-- ---------------------------------------------------------------------- -->
<label for="first_name">First Name</label><input id="first_name" maxlength="40" name="first_name" size="20" type="text" /><br>
<label for="last_name">Last Name</label><input id="last_name" maxlength="80" name="last_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="company">Company</label><input id="company" maxlength="40" name="company" size="20" type="text" /><br>
<label for="phone">Phone</label><input id="phone" maxlength="40" name="phone" size="20" type="text" /><br>
Subject:<textarea id="00N1600000EgFuw" name="00N1600000EgFuw" rows="3" type="text" wrap="soft"></textarea><br>
Contact me:<input id="00N1600000EvgRY" name="00N1600000EvgRY" type="checkbox" value="1" /><br>
newsletter:<input id="00N1600000EvgRd" name="00N1600000EvgRd" type="checkbox" value="1" /><br>
<input type="submit" name="submit">
</form>
That's what the web-to-lead from SFDC generates, and seems to work now.
However they have 2 questions I am not certain about and would love assistance with:
1) The specs for the new site require that the return page be the one the form was sent from (I.e., no redirection; we’re intending to do the equivalent of a “thanks” page as a pop-up onClick() — how is that accomplished through the API? I’d EXPECT that sending an empty retURL value should do it, but we just get back a blank page with a salesforce.com URL;
2) is it possible to customize the “name” parameter for the two checkbox fields (if not then we have to hack the entire form in the Django template without making it possible for Django to render the form natively since you can’t have a model form field name start with a digit…). This isn’t THAT problematic, but I’d like to know for future reference.
If anyone has any insight, I'd love to hear it and pass it along to them!
Many thanks.
Not sure your solution.
The common way that you could using the Partner WSDL or Enterprise WSDL to insert,update,upsert ,delete your data
Parnter WSDL:
not custom from your salesforce org, but it could be common way to get your data.
In python your could use this package
https://pypi.python.org/pypi/pyforce/1.4
And reference by this
https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_partner.htm
Enterprise WSDL will show your salesforce org status (including field and object) . But one your objects or fields are changing that it might be error.
So i suggest using api to control the redirect function and the action.
My solution is as follows in an example
from captcha.fields import ReCaptchaField
from django.conf import settings
def set_field_html_name(cls, new_name):
"""
This creates wrapper around the normal widget rendering,
allowing for a custom field name (new_name).
"""
old_render = cls.widget.render
def _widget_render_wrapper(name, value, attrs=None):
return old_render(new_name, value, attrs)
cls.widget.render = _widget_render_wrapper
class WebToLeadForm(forms.Form):
# <keep all fields here>
# example field below
referred_by = forms.CharField(label="Referred By", required=False)
# The reCAPTCHA in this form uses keys from settings.
captcha = ReCaptchaField()
set_field_html_name(referred_by, settings.SF_REFERRED_BY)
settings.py
SF_REFERRED_BY = '00xxxxxxxxxxxx'

Connect to a Web Service from A JSP Page Using Axis and Tomcat

I am trying to access a web service that I created in Eclipse Indigo. I have all the files, the classes and and the Wsdl file all created. Below is my index.jsp and what happens here is that I return a law company depending on the case and court selected. But What I have failed to find is how to connect to them through a dynamic page i.e. a JSP page. Any advice is highly appreciated
<%# page language="java" contentType="text/html; charset=ISO-8859-1"pageEncoding="ISO- 8859-1"%>
<%# page import="java.net.URL,javax.xml.namespace.QName,java.net.URL,,javax.xml.ws.Service,org.lao.ws.Findlawyers;"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Law Courts Home Page</title>
</head>
<body>
<form action="index.jsp" method="get">
<select name="selectcourt" id="selectcourt">
<option value="concourt">Constitutional Court</option>
<option value="highcourt">High Court</option>
<option value="magcourt">Magistrates Court</option>
<option value="supremecourt">Supreme Court</option>
</select>
<input type="radio" name="Case Type" value="casecivil" id="CaseType_0" />
Civil</label>
<br />
<label>
<input type="radio" name="Case Type" value="casecriminal" id="CaseType_1" />
Criminal</label>
<%
String casetype = "";
String selcourt = "";
String lawyers = "";
%>
<%=lawyers %></th>
</form>
</body>
</html>
You can do it 2 ways,either by sending the form (except for the jsp tags content) to the servlet and dislay the lawyers on a new page or else pass the selected parameters using ajax to the servlet and display the results on the same page.
Also since you seem to be new to this,its better you try with my first option.Passing a simple form something like this
<form action="index.jsp" method="get">
<select name="selectcourt" id="selectcourt">
<option value="concourt">Constitutional Court</option>
<option value="highcourt">High Court</option>
<option value="magcourt">Magistrates Court</option>
<option value="supremecourt">Supreme Court</option>
</select>
<input type="radio" name="Case Type" value="casecivil" id="CaseType_0" />
Civil</label>
<br />
<label>
<input type="radio" name="Case Type" value="casecriminal" id="CaseType_1" />
Criminal</label>
</form>
Then in your servlet retrieve the paramters like this
String casetype = request.getParamter("Case Type");
String selcourt = request.getParamter("selectCourt");
Then use this to find data from database
Then query use these paramters in a query and get the desired results..

How can I access data sent in a post request in Django?

I have a form that is supposed to create a new 'Quote' record in Django. A 'Quote' requires a BookID for a foreign key.
This is my form
<form method="POST" action="{% url 'quotes:createQuote' %}">
{% csrf_token %}
<section>
<label for="q_text">Quote Text</label>
<input type="text" name="text" id="q_text" placeholder="Enter a Quote" style="padding-left:3px"> <br>
<label for="q_book">Book ID</label>
<input type="text" name="bookID" id="q_book" placeholder="Enter Book ID" style="padding-left:3px"> <br>
<label for="q_disp">Display Quote Now?</label>
<input type="radio" name="display" id="q_disp" value="True"> True
<input type="radio" name="display" value ="False">False <br>
<button value="submit">Submit</button>
</section>
</form>
And this is the method that it is targeting
def createQuote(request):
#b = get_object_or_404(Book, pk=request.bookID)
return HttpResponseRedirect(reverse('quotes:index'))
Somewhere in that request argument I assume there is some sort of field that contains the bookID the user will pass in on the form. How do I get at that information?
Bonus points for anyone who can tell me some way I can visualise data like I might with console.log(some.collection) in Javascript
if request.method == "POST":
book_id = request.POST['book_id']
Assuming you're sure it's in there. Otherwise you'll need to verify/provide a default value like you would for a normal python dictionary.
As for visualising the data, do you mean printing it to the console? In which case if you're running the django runserver you can just do print some_data. If you want it formatted a little nicer, you can use pretty print:
import pprint
pp = pprint.PrettyPrinter()
pp.pprint(some_data)

is this a xss attack,why it is invalid?

To test a xss attack,i have the following code :
<html>
<head><title>test xss</title></head>
<body>
<input type="text" id="my_user_name_show" value="">
<script>
var s = '"/><script>alert(\'xss\');</script><br class="';
document.getElementById('my_user_name_show').value= s;
</script>
</body>
</html>
why can't the code trigger the alert(xss)?
XSS attacks against input form values have to be triggered from the backend when the actual HTML is changed, thus causing
<input type="text" id="my_user_name_show" value=""/>
<script>alert('xss');</script>
<br class="">
to be written, which obviously will cause it to trigger an alert. On the other hand your code will simply cause
<input type="text" id="my_user_name_show" value="\"/><script>alert('xss');</script><br class=\"">
to be placed inside the DOM, thus not causing any alert, because no script element is added to the DOM.

jQuery date picker refuses to work

Hey, any ideas why this wont work, when i click on the input fields, nothing happens. Here is the code:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript" src="js/ui.datepicker.js"></script>
<script type="text/javascript" charset="utf-8">
$(function()
{
$('.date-pick').datePicker();
});
</script>
This my form:
<form id="form1" name="form1" method="post" action="chart.php">
<ul id="add_form">
<li><label>Date from</label>
<input type="text" name="date1" class="date-pick" /></li>
<li><label>Date to</label>
<input type="text" name="date2" class="date-pick" value="<?php echo date("Y-m-d") ?>" /></li>
<li><label>Display</label>
<select name="type">
<option value="1">User Joins</option>
<option value="2">Messages sent</option>
<option value="3">Optin/outs</option>
</select>
</li>
</ul>
<br clear="all" /><br />
<input type="image" src="images/show.jpg" border="0" alt="Submit Form" class="login" />
</form>
I think you want a lowercase p.
$('.date-pick').datepicker();
To me it seems that you want...
$('.date-pick').datepick();
But I'm looking at the 3.7.4 version of Datepicker (freshly downloaded from the jQuery site). Based on your element that imports the Datepicker plugin, I'm not sure we're looking at the same version.
My example works for me using your markup.
Are you including jQuery.ui.core js file?
Are you including the DatePicker CSS files (ui.core.css and ui.datepicker.css)? Sometimes it works but you can't see it the way it should look because there are no styles in place.