I'm quite new in web development, have only couple of weeks of experience.
Currently working on C# website and can't get ReCaptchaV3 to work.
I have a subscribe form that shows up as a modal when user clicks on a "subscribe" button on the bulletin page.
In the form I have hidden input field: <input type="hidden" name="Google-captcha-token" id="GoogleCaptchaToken">
It generates the token when "Sign Up" button of the form is clicked.
My problem is - how to I get a hold of that value on the backend in C#? and then send it to google for verification? I also need to check if value I got from Google is within needed range and everything is good continue submitting the form.
This is where I stuck. I understand that I need to catch that value and work with it in the controller, but don't know how to do that.
Hope someone can help me out on this one.
This is how the code in the controller looks
public class BulletinController : _SharedController {
public ActionResult Index(int p = 0) {
var perPage = 10;
if (p < 1) {
p = 1;
}
var starting = (p * perPage) - perPage;
if (starting < 0) {
starting = 0;
}
var token = HttpContext.Request.Form["Google-captcha-token"];
var ns = new NewsServices();
var newsArticles = ns.GetNewsArticles(starting, perPage);
var count = ns.GetNewsArticlesCount();
ViewBag.Paging = Pagination.Generate(count, starting, perPage);
return View(newsArticles);
}
public ActionResult Details(int id) {
var article = new NewsServices().GetNewsArticleByID(id);
if (article == null) {
return HttpNotFound();
}
return View(article);
}
}
I watched a lot of videos on how it should be done, but none of them worked.
It seems to be a problem that view of the page is already using a model and that model is autogenerated. So looks like I can't use another model. Current model is also a list model (not sure what that exactly means though).
The other thing is that submission of the form is not going through the back-end and done through the constantcontact JavaScript sign up script.
Hope somebody will be able to help. Thanks.
Related
I'm trying to retrieve the page index of a selected object of the grid that is using ServerOperation, but I don't know how would I do that without too much complication.
Currently, I'm receiving an Id from the URL (https://...?ObjectId=12) and I will select this item in the grid, but first I have to show the page it is, so I'm trying to get the page number of this row.
The problem is that I'm using ServerOperation(true). In addition, I'm retrieving the paged list without any filters.
function _displayDetailsModal(id, selectRow = true, focusSelected = true) {
$(document).ready(() => {
var url = `${urls.Details}/${id}`;
if (selectRow) {
// GET PAGE OF ITEM THEN
// CHANGE TO PAGE THEN
kendoGrid.selectById(id);
}
if (focusSelected) {
kendoGrid.focusSelected(); // Scrolls to selected row.
}
loadModal(url);
});
}
Is this the kind of thing you are after?
Dojo: https://dojo.telerik.com/iNEViDIm/2
I have provided a simple input field where you can set the page number and then a button which will change the page to the selected page for you.
All I am doing is setting the datasource's page via the page method and then it will go off and make a read to the remote datasource for you and then return that page of data.
$('#btnPage').on('click',function(e){
var page = $('#pageNumber').val();
$('#pageLabel').html('Page Selected Is: ' + page);
var ds = $('#grid').data('kendoGrid').dataSource;
ds.page(parseInt(page));
});
If you select a page higher than the last available then it will just show the last page.
More info can be seen here: https://docs.telerik.com/kendo-ui/api/javascript/data/datasource/methods/page
If you need any further info let me know:
I ended up doing it on the server. That is how I did it:
Controller.cs
Instead of sending just the usual ToDataSourceResult, I add two fiels (PageIndex and ObjectId), and send it to the front-end to change the page and select the row.
[HttpPost("List")]
public IActionResult List([DataSourceRequest] DataSourceRequest request, RequestActionViewModel requestAction)
{
// Getting the pageIndex of the ObjectId present in requestAction.
var objectIndex = elementList.FindIndex(el => el.Id == requestAction.ObjectId) + 1;
var objectPageIndex = Math.Ceiling((decimal)objectIndex / request.PageSize);
var dataSourceResult = elementList.ToDataSourceResult(request);
return Json(new {
Data = dataSourceResult.Data,
Total = dataSourceResult.Total,
AggregateResults = dataSourceResult.AggregateResults,
Errors = dataSourceResult.Errors,
// Extra fields
PageIndex = objectPageIndex,
ObjectId = requestAction.ObjectId
});
}
index.js
I Get from the server the page and the id of the element, select the change the page of the grid, and select the element.
function onGridRequestEnd(e) {
this.unbind("requestEnd", onGridRequestEnd);
if (e.PageIndex) {
kendoGrid.bind("dataBound", function temp() {
// Custom method.
kendoGrid.selectById(e.ObjectId, e.PageIndex);
// To avoid looping.
kendoGrid.unbind("dataBound", temp);
});
}
}
I have a Marketo form with one field called sharedURL. I set this as a text field because the URL field is too restrictive, as you may have guest it is a field which allows people to input a URL. The field should only accept certain domains before moving on to the defined Landing page. Lets assume the only acceptable domains are www.marketo.com, http://www.marketo.com, https://www.marketo.com etc (all variations of the domain). I looked at multiple suggested solutions on various external sites and marketo sites but couldnt manage to tweak the code to fit my requirement. This is what I got (inserted in the HTML in a guided landing page template) my Form and field details are (if its needed). My solution did not work... any help appreciated....
"Id":6466,"Name":"sharedURL","Datatype":"string","Maxlength":512,"
(function() {
// Domains that can only be used
var validDomains = [
'https://info.marketo.com',
'https://www.marketo.com',
'http://www.marketo.com',
'info.marketo.com',
'www.marketo.com',
],
MktoForms2.whenReady(function(form) {
form.onValidate(function() {
var url = form.vals().sharedURL;
if (url) {
if (!isurlGood(url)) {
form.submitable(false);
var urlElem = form.getFormElem().find("#sharedURL");
form.showErrorMessage("You must use an approved Domain.", urlElem);
} else {
form.submitable(true);
}
}
});
});
function isurlGood(url) {
for (var i = 0; i < validDomains.length; i++) {
var domain = validDomains[i];
if (url.indexOf(domain) != -1) {
return false;
}
}
return true;
}
})();
Ok, I have a weird behavior issue on an mvc view that I am working on. The form is for employee onboarding, so it collects information about the new employee. I have a dropdown list of job titles that is strongly typed.
The weird part of this is that this does not work upon the first change of the Job Title dropdown. It does everything but show the checked box. It does work fine though for subsequent change events. I have tracked the firing events using alert boxes. When those alerts show, it all works. When I comment out the alerts, the weird behavior returns.
The logic is as follows:
A job title is selected; jquery detects the change event.
A call to the controller is made and the controller returns a partial view comprised of one field (SelectedAppsList).
Jquery function clears the Application(s) Checkboxes
Jquery is called to check checkboxes of Applications based upon the returned values in SelectedAppsList.
Wizard View:
$("#JobId").change(function () {
//alert($("#JobId").val());
// Check the Apps Based Upon the Job Title
var jobId = $("#JobId").val();
$("#dvApps").load('#(Url.Action("GetApps", "ESRWizards", null, Request.Url.Scheme))?jobId=' + jobId);
AutoCheckSelectedApps();
}));
function AutoCheckSelectedApps() {
ClearSelectedApps();
//alert("Selecting Apps...");
var apps = $("#SelectedAppsList").val().split('|');
for (var i = 0; i < apps.length; i++) {
//alert(apps[i]);
if (apps[i] != "") {
$('input[type="checkbox"][id="SelectedApps_' + apps[i] + '"]').attr('checked', true);
}
}
};
function ClearSelectedApps() {
//alert("Cleared...");
$('input[type="checkbox"][id^="SelectedApps_"]').attr('checked', false);
}
Wizard View Form Controls Involved:
`#Html.DropDownList("JobId", String.Empty)`
`<input type="checkbox" name="SelectedApps_#item.Id" id="SelectedApps_#item.Id" value="#item.Id" />`
and partial view below.
Controller:
[HttpGet]
[OutputCache(Duration = 0)]
public ActionResult GetApps(int jobId)
{
ViewBag.SelectedAppsList = null;
var AppList = db.JobApps.Where(m => m.JobId == jobId).OrderBy(v => v.AppId);
foreach (var item in AppList)
{
ViewBag.SelectedAppsList += item.AppId.ToString() + "|";
}
return PartialView("_Apps");
}
Partial View _Apps
#model ECSR.Models.ESRWizard
#if(ViewBag.SelectedAppsList != null)
{
#Html.TextBox("SelectedAppsList", (string)ViewBag.SelectedAppsList)
}
else
{
#Html.TextBoxFor(m => m.SelectedAppsList)
}
I am guessing that this is a possible refresh issue, so I tried various refresh commands on the checkboxes to no avail. This is a long form so I stripped out the non-related form fields. Any ideas?
first of all, I don't want to use "...driver.FindElement..." or any another way that I must to inform any kind of locator like id/xpath/name.
Is there some way to get the id information of a webElement, just clicking on it using C# or Java?
I would like to do something like Selenium IDE does:
1 - MANUALLY to open browser(IE/Firefox/Chrome..) and access an URL.
2 - MANUALLY to click on some field/element on the page and save its respective id.
<div **id="ThisIsWhatINeed"**>
PS: After to get the id information, I need to handle this information on others methods, so I think that the "step 2" above, should be something like a listener with a function returning a string.
Here we go:
private Int32 GetTableRowCount(string tableID)
{
Int32 count = 0;
if (webBrowser1.Document != null)
{
HtmlElement tableElem = webBrowser1.Document.GetElementById(tableID);
if (tableElem != null)
{
foreach (HtmlElement rowElem in tableElem.GetElementsByTagName("TR"))
{
count++;
}
}
else
{
throw(new ArgumentException("No TABLE with an ID of " + tableID + " exists."));
}
}
return(count);
}
Here you may find some information: enter link description here
I'm building a PDF in Scribus and stumbling through javascript (basic newbie here) as I go. I've ran into an issue and I can't seem to find a good answer.
I have a combobox called productType where a user selects a product. Once they do that I want a text field called mortClause to display the proper clause. I've placed the following code under the combobox's Action -> On Blur -> Javascript.
Here is what I have that is not working:
var ckSelect = this.getField("productType");
var ckResult = this.getField("mortClause");
if (ckSelect.value === "VA") {
mortClause.value = 'VA Clause';
} else if (ckSelect.value === "FHA") {
mortClause.value = 'FHA Clause';
} else {
mortClause.value = 'Normal Clause';
}
"mortClause" is not the name of your variable, its ckResult.
If you change
mortClause.value = 'VA Clause';
to
ckResult.value = 'VA Clause';
you get the expected behaviour.
But you probably already know that. or gave up, after 3 years.