URL address availability - auto verification - verification

I have an input that's in form. I enter the URL adress into this input, click sumbit, and below it shows if this address is available or not. This is done.
Now I want to make this information show up automatically (without clicking submit), after making a change in the input? I would also like the value in the input to not disappear after checking. How can I do that?
I would like it to look more or less like this, but instead of email correctness, URL availability - https://youtu.be/HzJngc-Se9Q
<form action="" method="GET" name="form1" id="form1">
<div id="custom-search-input">
<div class="adress-div">
<input type="text" id="ok" name="domain" maxlenght="30" class="adress" pattern="(.{1,})?([.]{1})?.+[.]{1}.+" placeholder="np. www.page.com" title="Enter URL adress." autocomplete="off" required/>
<br>
<input type="submit" class="button2" value="Check!">
</div>
</div>
</form>
<?php
error_reporting(0);
if(isset($_GET['domain'])){
$domain = $_GET['domain'];
$godaddycheck = 'https://in.godaddy.com/domains/searchresults.aspx?checkAvail=1&tmskey=&domainToCheck='.$domain.'';
$namecomcheck = 'https://www.name.com/domain/search/'.$domain.'';
$registercomcheck = 'http://www.register.co, m/domain/search/wizard.rcmx?searchDomainName='.$domain.'&searchPath=Default&searchTlds=';
if ( gethostbyname($domain) != $domain ) {
echo "<br><br><h1 style='color: #e30000;'><b>$domain</b> not available.</h1>";
}
else {
echo "<br><br><h1 style='color: #00e339;'><b>$domain</b> available.</h1><h2>
</h2>";
}
}
?>

This is not possible doing only with PHP.
You will need to do that with JavaScript. Therefore you need to
listen on an input change for your <input>field
Send the value of the input field with AJAX (https://developer.mozilla.org/en-US/docs/Web/Guide/AJAX/Getting_Started) to a PHP script, which then validates the domain
Fetch the response and display it to the user
But there are a lot of tutorials out there, how to do that. For example: https://www.w3schools.com/php/php_ajax_php.asp

Related

only first word from radio button selection is being returned

To get the selected option from a radio button form, I'm looking at request.vars to get the value. Following is the controller code:
def get_results():
test = request.vars['QuestionOne']
for topic in session.selectedtopics:
test = test + request.vars[topic]
return locals()
And now the code for the view:
{{extend 'layout.html'}}
<P>Please select the options that most closely approximates the actual scenario.
<br>
<form action="{{=URL('get_results')}}" method="post">
{{nameTopic =""}}
{{session.selectedtopics = list()}}
{{for topic in topics:}}
{{if nameTopic <> topic.topic.replace(" ", "_"):}}
<br><h2>{{=topic.topic}}</h2>
{{nameTopic = topic.topic.replace(" ", "_")}}
{{session.selectedtopics.append(nameTopic)}}
{{pass}}
<p><input type="radio" name={{=nameTopic}} value={{=topic.param}}>{{=topic.param}}</p>
{{pass}}
<br>
<input type="submit">
</form>
Here is the problem: I don't know the reason, but it is getting only the first word of the selected option in the radio form. For example, the option selected is "It is normal", but the var is returning only "It". Any idea why it is happening?
Thank in advance.
You need to quote the HTML attribute values:
<input type="radio" name="{{=nameTopic}}" value="{{=topic.param}}">
Without the quotes, you'll end up with final HTML like:
<input type="radio" name=some_topic value=It is normal>
The browser will interpret the value to be "It", with "is" and "normal" being invalid HTML attributes.

How to add name value to input element

I am looping a data, from the data, I am adding the name value into the input field, but not at all set. what is the issue here?
My form template:
<form novalidate name="myForm">
<div ng-show="myForm[addVas.name].$error.pattern">Error will come </div>
<div class="form-group">
<input type="text" [(ngModel)]="addVas.input" [attr.disabled]="addVas.disabled ? '' : null " name="{{addVas.name}}" ng-pattern="/^[0-9]/" (blur)="addAdnlVasAfterInput(addVas)" placeholder="Provide value of shipment"
class="form-control">{{addVas.name}} <!--getting value here-->
</div>
</form>
I am not getting throw the error, when user input instead of number in to charters. how to solve that?
Now I have update my name field in to [name]="addVas.name" but I not confirm the name sent, unless if i get error message
There are some confusions between Angular versions. ng-show should be *ngIf or [hidden] with reverse logic, ng-pattern is [pattern]. [attr-disabled] can be [disabled], etc.. Pattern /^[0-9]/ doesn't allow more than 1 digit, I am not sure it was your aim. If you use a property as pattern expression, the use [pattern]="property":
Here is what I suggest:
<form #myForm>
<input type="text" [(ngModel)]="addVas.input"
[disabled]="addVas.disabled" [pattern]="addVas.pattern"
[name]="addVas.name" #input="ngModel">
<div *ngIf="input.errors && (input.dirty || input.touched)" >
<div [hidden]="!input.errors.pattern">
Should be a number
</div>
</div>
</form>
Demo
The properties cannot perform interpolation.
You need to use property binding for setting values to properties.
Try this:
[name]="addVas.name"
instead of
name= "{{addVas.name}}"

Best way to handle filling fields when behat testing and fields have the same name

I have a login page for a site that has three types of users. The user clicks on his/her type and the un/pw field appears, depending on whatever type the user clicks on. However, in the page source all three forms are there but two are hidden depending on which type has been selected. I'm trying to write a behat test to test logging each type of user in. My behat test looks like this:
#javascript #core
Feature: Secure Login
As a User
I expect to be asked for my credentials
So that I can use the system securely
Background:
Given I am logged out
Scenario: Failed User1 Login
When I go to user1 interface
When I submit incorrect user1 credentials
Then I should stay logged out
And I should see "The username or password entered does not match our records."
Scenario: Successful User1 Login
When I go to user1 interface
When I submit correct user1 credentials
Then I should be logged in to user1 interface
Scenario: Failed User2 Login
When I go to user2 interface
When I submit incorrect user2 credentials
Then I should stay logged out
And I should see "The username or password entered does not match our records."
Scenario: Successful User2 Login
When I go to user2 interface
When I submit correct user2 credentials
Then I should be logged in to user2 interface
When I view the page source, here's what I see for the forms:
<form id='user1' name='user1' method="post" role="form">
<input type="hidden" name="subsystem" value="user1"/>
<label for="un1" class="label">Username</label>
<div id="un_inst1"class="label_instruction"></div>
<input autocapitalize="off" id="un1" autocorrect="off" type="text" name="username" value="" style="margin-bottom: 10px" aria-describedby="un_inst1">
<label for="pw1" class="label">Password</label>
<div id="pw_inst1"class="label_instruction"></div>
<input type="password" id="pw1" name="password" style="margin-bottom: 10px;" aria-describedby="pw_inst1">
<div class="login_buttons">
<input type="submit" value="Go" class="btn_go input-submit">
<input type="reset" class="btn_reset input-reset" value="Reset">
<br/>
</div>
</form>
<form id='user2' name='user2' method="post" role="form">
<input type="hidden" name="subsystem" value="resident"/>
<div class="usr-login label">Resident Login</div>
<label for="un2" class="label">Username</label>
<div id="un_inst2"class="label_instruction"></div>
<input autocapitalize="off" autocorrect="off" type="text" id="un2" name="username" value="" style="margin-bottom: 10px" aria-describedby="un_inst2">
<label for="pw2" class="label">Password</label>
<div id="pw_inst2"class="label_instruction"></div>
<input type="password" id="pw2" name="password" style="margin-bottom: 10px;" aria-describedby="pw_inst2">
<div class="login_buttons">
<input type="submit" value="Go" class="btn_go input-submit">
<input type="reset" class="btn_reset input-reset" value="Reset">
<br/>
</div>
</form>
In my featurecontext file, I have these functions:
public function iSubmitIncorrectCredentials($interface)
{
$button ='Go';
return $this->login("tester" . time(), "bar", $button);
}
private function login($username, $password, $btn)
{
$this->fillField('username', $username);
$this->fillField('password', $password);
$this->pressButton($btn);
}
Where the $interface is for user1 or user2. The problem that I'm having is that the tests for user1 pass, but when I get to user2 tests I get this error:
{"errorMessage":"Element is not currently interactable and may not be manipulated","request":{"headers":{"Accept":"application/json;charset=UTF-8","Content-Length":"36","Content-Type":"application/json;charset=UTF-8","Host":"127.0.0.1:8643"},"httpVersion":"1.1","method":"POST","post":"{\"value\":[\"tester1479232631\\ue004\"]}","url":"/value","urlParsed":{"anchor":"","query":"","file":"value","directory":"/","path":"/value","relative":"/value","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/value","queryKey":{},"chunks":["value"]},"urlOriginal":"/session/ea0f7000-ab5c-11e6-acb9-5946ec8fdb06/element/:wdc:1479232631203/value"}} (WebDriver\Exception\InvalidElementState)
What I think is happening is that fillField() is trying to find the username field, but there are two, so for user1 the tests work but for user2, I get the error. I'd like some advice on how to handle this, besides changing the name of the un/pw fields.
Thanks
You need to have different selectors for each form. You can do this in few ways:
For the first 2 methods you will need to use another method to fill the elements and click the fields since you will use css selectors.
For example: find the element -> click() and find the element -> setValue()
1) create a method for each type with different selectors
loginWithUser1($username, $password){...}
loginWithUser2($username, $password){...}
loginWithUser3($username, $password){...}
You will need to use css selectors for the elements like:
#user1 input[name=username]
#user1 input[name=password]
2) use the same method and build/read selector from an array based on a parameter
login($username, $password, $role)
{
}
3) use page object functionality
This option will use a method same as the second one but instead of reading selectors from an array you will use a getElement() method and use the methods you need on that object. Please see here an example working with elements
I recommend to try the last option and if you can't make it work to try with the second one.
Tip: Avoid passing parameters in the method that you don't need like $btn from your login method.The method should know about the button element, you need to pass data only.

Cgi C program return value to main HTML and display result

I am programming a server side script on an Apache machine with cgi. I am using C for the cgi programming. I am a total noob and learning from online examples(I must say except the basics I didn't come across more web sources for detailed learning!).
I am having a simple HTML page where the username(input) is added to a list which is a file I have in my system and then the updated list should be displayed in the SAME PAGE.
I am not able to "print" the results of both the script and http link on the same page so therefore in the code below, you will only see buttons. Please help.
Here is what I have:
Html:
<html>
<head><title>Home</title></head>
<body>
<h1>REGISTER</h1>
<form action= "/cgi-bin/mycgi.cgi" name ="create user" method ="get">
Enter name:<input type="text" name="user">
<br>
<input type="submit" value="add">
</form>
<FORM action="http://localhost:8000/getusers/" method="get">
<P>
<input value="Display Users" type="submit">
</P>
</FORM>
</body>
Here is the cgi Code:
#include<stdio.h>
#include<string.h>
int main(){
char *tmpStr;
char *user;
printf("Content-Type:text/html\n\n");
printf("<html><head><title></title></head><body>");
tmpStr = getenv("QUERY_STRING");
while(tmpStr && *tmpStr != '='){
tmpStr++;
}
user = tmpStr+1,
printf("Adding %s to User Database",user);
//system("wget http://localhost:8000/newuser/");//call script to add user?
printf("</body></html>");
return 0;//return user?
}
Could you please tell me how I can realize these? How can I display the user list without opening a new html site? Also in the above C code, I have to call the link "http://localhost:8000/newuser/" which returns a success or failure value. How can I return it to the parent form?
Thanks.
You could add an iframe to your html:
<iframe id="theiframe" name="theiframe"></iframe>
And then setting the target of your form to the iframe:
<form action= "/cgi-bin/mycgi.cgi" name ="create user" method ="get" target="theiframe">
Anyway, it is not clear to me if the updated list should be displayed when you click on the first or second button.

Wiring template form actions with Python code

I'm working on a website that has a “Sign up” page which should be callable from anywhere in the site.
I have the following dummy interface and implementation for the “user” product:
Interface:
##
## located in bahmanm/sampleapp/interfaces.py
##
class ISampleAppUser(Interface):
"""
"""
Implementation:
##
## located in bahmanm/sampleapp/implementation/SampleAppUser.py
##
class SampleAppUser:
"""
"""
implements(ISampleAppUser)
# Note that this method is outside of the implementation class.
#
def manage_addSampleAppUser(self, id, title):
# ...
Now, for the moment, let's assume there's a link on the index page which leads to the following template (Sign up template):
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns="http://xml.zope.org/namespaces/tal">
<head><title>Add a new User</title></head>
<body>
<h2>Add a user instance</h2>
<form action="#" method="POST"
tal:attributes="action python:'manage_addSampleAppUser'">
<p>Id: <input type="text" name="id"/></p>
<p>Title: <input type="text" name="title"/></p>
<input type="submit" value="Add"/>
</form>
</body>
</html>
However I haven't been able to find the right value for action property of the form; all I get is a “resource not found”.
Honestly, I believe it's a problem of understanding Zope's mechanisms on my side. I'd really appreciate any hints/clues on where should I go digging for the solution, configure.zcml or the implementation or the template itself. TIA,
You really want to create a view for that; you can call a Product factory like that from a URL too, but it is not recommended.
With a view, you can combine the form and the code to create the new user in one place:
from zope.publisher.browser import BrowserPage
from sampleapp.implementation.SampleAppUser import manage_addSampleAppUser
class NewUserSignup(BrowserPage):
def __call__(self):
# called when the view is being rendered
if 'submit' in self.request:
# form was submitted, handle
self.addUser()
return self.index() # render the template
def addUser(self):
# extract form fields from self.request.form
# validation, error handling, etc.
if someerror:
self.error = 'Error message!'
return
user = manage_addSampleAppUser(self.context, id, title)
# add things to this new user if needed
# all done, redirect to the default view on the new user object
self.request.response.redirect(user.absolute_url())
then register this view with something like:
<browser:page
for="*"
name="signup"
class=".signup.NewUserSignup"
template="signup.pt"
permission="zope.public"
/>
When your new page is registered, the named template is added as a index attribute on your NewUserSignup class, so the __call__ method can invoke it (self.index()) and return the results.
Because you combined the signup handling and the template together, you can now easily incorporate error handling. When someone loads the page for the first time self.request.form will be empty, but as soon as someone hits the submit button, you can detect this and call the addUser method.
That method can either create the user and then redirect away from this page, or set an error message and return, at which point the form is re-rendered.
This makes the action easy to set; you could just leave it empty, or you can set it to the current context URL plus the name of the view. Together, the template then becomes:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns="http://xml.zope.org/namespaces/tal">
<head><title>Add a new User</title></head>
<body>
<h2>Add a user instance</h2>
<div class="errormessage" tal:condition="view/error|nothing" tal:content="view/error">
Conditional error message appears here
</div>
<form action="#" method="POST"
tal:attributes="action string:${context/absolute_url}/##${view/__name__}">
<p>Id: <input type="text" name="id"
tal:attributes="value request/form/id|nothing" /></p>
<p>Title: <input type="text" name="title"
tal:attributes="value request/form/title|nothing" /></p>
<input type="submit" value="Add" name="submit"/>
</form>
</body>
</html>
Note how the form inputs are pre-filled with existing data from the request as well, making it easier for your visitor to correct any errors they may have made.