I am trying to get a simple form to post to my sql database, but nothing is happening when i click on it. I have tried runat="Server, onclick, onserverclick tags but nothing is happening.
I am new to html forms so dont know if i should have the button outside of the actual form to do this? any help is greatly appreciated
Below is the html code
<div class="register-content" ">
<form method="POST" class="margin-bottom-0">
<label class="control-label">Name <span class="text-danger">*</span></label>
<div class="row row-space-10">
<div class="col-md-6 m-b-15">
<input id="First_Text" type="text" class="form-control" placeholder="First name" required />
</div>
<div class="col-md-6 m-b-15" >
<input id="Last_Text" type="text" class="form-control" placeholder="Last name" required />
</div>
</div>
<label class="control-label">Email <span class="text-danger">*</span></label>
<div class="row m-b-15">
<div class="col-md-12">
<input id="Email_Text" type="text" class="form-control" placeholder="Email address" required />
</div>
</div>
<label class="control-label">Password <span class="text-danger">*</span></label>
<div class="row m-b-15">
<div class="col-md-12">
<input id="Pass_Text" type="password" class="form-control" placeholder="Password" required />
</div>
</div>
<div class="register-buttons">
<button runat="server" onserverclick="ValidateUser" type="button" class="btn btn-primary btn-block btn-lg">Sign Up</button>
</div>
<div class="m-t-20 m-b-40 p-b-40">
Already a registered user? Click here to login.
</div>
<hr />
<p class="text-center">
© NZAB All Right Reserved 2019
</p>
</form>
</div>
And here is the code behind
Protected Sub ValidateUser(sender As Object, e As EventArgs)
Dim connect As New SqlConnection(ConfigurationManager.ConnectionStrings("NZABFMAD_Users").ToString())
Using coa As New SqlCommand()
With coa
.Connection = connect
.CommandType = CommandType.Text
End With
Try
connect.Open()
Dim insertcmd As String
insertcmd = "INSERT INTO [New_User] (Username,[First name],[Last name],Email,Password) values (#User_Text,#First_Text,#Last_Text,#Email_Text,#Pass_Text)"
coa.CommandText = insertcmd
coa.Parameters.AddWithValue("#User_Text", Request.Form("User_Text"))
coa.Parameters.AddWithValue("#First_Text", Request.Form("First_Text"))
coa.Parameters.AddWithValue("#Last_Text", Request.Form("Last_Text"))
coa.Parameters.AddWithValue("#Email_Text", Request.Form("Email_Text"))
coa.Parameters.AddWithValue("#Pass_Text", Request.Form("Pass_Text"))
coa.ExecuteNonQuery()
connect.Close()
MsgBox("success insert")
Catch ex As Exception
MsgBox("Fail to Save to database")
End Try
End Using
End Sub
Granted i will be salting/hashing passwords when storing in sql, but for now i just want the button to actually fire the event!
First of all you need to give each input field a name, as that is what identifies them when posted to the server. The id is merely for client-side identification (e.g. via JavaScript).
<input id="First_Text" name="First_Text" type="text" class="form-control" placeholder="First name" required />
Secondly, the button merely calls the callback on the server. It doesn't actually submit the form, so in this case Request.Form will be empty.
For standard HTML forms you need to use an <input type="submit"/> so that your form is actually submitted and its data sent to the server. You can then invoke the reading of its data from the Page_Load handler.
<div class="register-buttons">
<input type="submit" class="btn btn-primary btn-block btn-lg" value="Sign up"/>
</div>
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'Check if this is a POST request.
If HttpContext.Current.Request.HttpMethod.Equals("POST", StringComparison.OrdinalIgnoreCase) Then
DoSignUp()
End If
End Sub
Private Sub DoSignUp()
'Put your code from ValidateUser here.
End Sub
Although you could, like Andrew Morton said in the comments, replace the form and your input fields with ASP.NET controls and handle it via postback instead. I'm not sure which method is preferred in this case as I haven't worked much with WebForms. Personally, I'd use a form like you do now.
Related
I am trying to send the data from the database to the Html form, but I'm getting an error like this
TypeError: 'ImmutableMultiDict' objects are immutable
this is the flask code for editing the data
#app.route('/edit-project/<string:id>', methods = ['GET', 'POST'])
def edit_project(id):
project = Project.query.get(id)
request.form['title'] = project.title
request.form['link'] = project.link
request.form['description'] = project.description
if request.method == 'POST':
title = request.form['title']
link = request.form['link']
description = request.form['description']
image = request.files['image']
image.save(os.path.join(app.config["IMAGE_UPLOADS"], 'project/'+ project.image))
return render_template('project/edit_project.html')
The Html template 'edit_project.html' is shown below
<div class="container">
<form method="POST" id="project-form" enctype="multipart/form-data">
<div class="form-group">
<input type="text" name="title" class="form-control" id="title" placeholder="Title">
</div>
<div class="form-group">
<input type="text" name="link" class="form-control" id="title" placeholder="Project Link">
</div>
<div class="form-group">
<label for="exampleFormControlTextarea1">Description</label>
<textarea id = project-form name="description" class="form-control" id="description" rows="3"></textarea>
</div>
<div class="input-group" style="width: 30%;">
<div class="input-group-prepend">
<span class="input-group-text" id="inputGroupFileAddon01">Upload</span>
</div>
<div class="custom-file">
<input type="file" name="image" class="custom-file-input" id="inputGroupFile01" aria-describedby="inputGroupFileAddon01">
<label class="custom-file-label" for="inputGroupFile01">Upload image</label>
</div>
</div>
<div class="form-group" style="padding-top: 2rem;">
<button type="submit" class="btn btn-primary">Publish</button>
</div>
</form>
</div>
Is there is any way to display the data in the form without using WTForms or do I've to use WTForms instead?
Thanks in advance.
Can you use jinja templating?
render_template() takes data argument. You can pass the data from your DB to that call and use jinja templates in HTML to render it. Setting the values of your input will do.
For example:
Your data is data = {title:"apple"}
And, return render_template("project/edit_project.html", data=data) will provide you data object in HTML file.
There, you can use jinja like this:
<div class="form-group">
<input type="text" name="title" class="form-control" id="title" placeholder="Title" value={{data.text}}>
</div>
Hope it helps!
Here is my vba code.
It works up until the point where I also keep getting messages that say object has disconnected from its client. I don't want to use sendkeys or Selenium as my colleagues will not be able to duplicate and run this form then. I wish to make it robust.
Sub exceltoweb()
Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")
IE.navigate "https://fans-dub.amazon.com/"
IE.Visible = True
While IE.Busy
Do
DoEvents
Loop Until IE.readyState = READYSTATE_COMPLETE
Wend
delay 5
IE.document.all("submitterId").Value = ("fahac")
delay 2
IE.document.all("to").Value = ("ceezeala")
delay 3
IE.document.all("messageText").Value = ("10 errors")
delay 3
IE.document.all("/images/send-button.gif").Click
Application.StatusBar = "Form Submitted"
Set IE = Nothing
Application.ScreenUpdating = True
End Sub
This is the HTML:
id="simpleSendMessageForm" method="post">
<div id="outerDiv">
<label>From:</label>
<div class="formElement">
<input name="submitterId" type="text" size="16" value="fahac" readonly />
</div>
<div class="break"></div>
<label>
<abbr title="A comma separated list of user ids who will receive this message">To:</abbr>
</label>
<div class="formElement">
<input name="to" type="text" size="16" value="" />
</div>
<div class="break"></div>
<label>
<abbr title="A comma separated list of manager's user ids. The message will be sent to all people who report directly to one of these managers">Direct reports of:</abbr>
</label>
<div class="formElement">
<input name="directReports" type="text" size="16" />
</div>
<div class="break"></div>
<textarea rows="5" name="messageText"></textarea>
</div>
<div class="break"></div>
<span class="right">
<span id="ssmf-loading" class="ajaxloading"><img src="/images/ajax-loading.gif" alt="Loading..." /></span>
<input type="image" src="/images/send-button.gif" />
</span>
</form>
</div>
</fieldset>
</div>
<!-- SEARCH -->
<!-- Search tab is excluded from EU pages for compliance with European data protection law -->
<div class="clear"></div>
<!-- MESSAGE LIST -->
<div class="qsection">
<fieldset class="roundborder snx2">
<legend id="messageListTitle" class="qsectionTitle">My Messages (Last 3 days)</legend>
<div id="myMessages" class="qsectionBody">
The boxes I want to enter a text into does not have an ID, just names. I wish to populate 3 boxes and hit send for which the send does not have ID either.
I think these links may help you:
http://automatetheweb.net/
http://automatetheweb.net/common-vba-methods-properties-web-automation/
I'm sure that you can find those elements using something like
"IE.document.getElementByName" or
"IE.document.getElementsByClassName"
change those values using .value
and click using click() method
I'm using this code for a form in HTML:
<div class="login-wrapper">
<form>
<div class="popup-header">
<span class="text-semibold"><i class="fa fa-sign-in"></i> Logging in</span>
</div>
<div class="well">
<div class="form-group has-feedback">
<label>Username</label>
<input type="text" name="user" class="form-control" placeholder="e.g. andre#mail.de">
<i class="icon-users form-control-feedback"></i>
</div>
<div class="form-group has-feedback">
<label>Password</label>
<input type="password" name="password" class="form-control" placeholder="Password">
<i class="icon-lock form-control-feedback"></i>
</div>
<div class="form-group has-feedback">
<label>reCaptcha</label>
<div class="g-recaptcha" data-sitekey="..."></div>
</div>
<div class="form-actions text-right">
<input type="submit" id="loginbutton" name="loginbutton" value="Login" class="btn btn-primary">
</div>
</div>
</form>
</div>
<!-- /login wrapper -->
However, when I press the submit button, it does nothing but giving me a very strange url in my browser's address bar:
http://localhost/?user=&password=&g-recaptcha-response=&loginbutton=Login
Whenever I fill out fields, it kind of puts the content into the URL:
http://localhost/?user=peter%40griffin.com&password=somepass&g-recaptcha-response=&loginbutton=Login
The intended PHP code which should be run when pressing the button won't even run or load, since this HTML stuff apparently screws things up. I don't know what I have done the wrong way. Any suggestions?
In order for the form to submit somewhere else, you need to set the form elements action parameter.
<form action="some_file.php">
Alternatively, you can take the query string and append it directly to the file path to test your script.
http://localhost/some_file.php?user=peter%40griffin.com&password=somepass&g-recaptcha-response=&loginbutton=Login
Inside of some_file.php, you would then pull out each of the variables like
$user = $_GET['user'];
$password = $_GET['password'];
The very strange url is actually the result of a GET request.
The parameters are separated by an & so you have:
user=peter%40griffin.com&password=somepass&g-recaptcha-response=
"User" is the attribute name of your input and "peter%40griffin.com" is the value
First you need to send your form to an action using the attribute action="save.php", for example an pass the parameters using the method="POST", so the user can't see the values in the URL.
<form action="save.php" method="post">
I am trying to get a balance checker for Adnooka, but I can't even get past the login.
Here's the HTML:
</div>
<div class="control-group row-fluid">
<label class="row-fluid " for="inputPassword">Password <div class="pull-right"><a class="muted"><small><a href='http://adnooka.com/recover'>Forgot your password ?</a></small></a></div></label>
<div class="controls row-fluid input-append">
<input type="password" id="inputPassword" placeholder="Password" name="password" class="row-fluid" value=""> <span class="add-on"><i class="icon-lock"></i></span>
</div>
</div>
<div class="control-group row-fluid fluid">
<div class="controls span6">
</div>
<div class="controls span5 offset1" style=''>
<button type='submit' class="btn btn-default" style='float:right'>Login<i class="gicon-chevron-right"></i></a>
</div>
</div>
But the Button has no ID or Name, how can I click it?
How how can I return the value of a balance?
Here's what I've got so far:
WebBrowser1.Document.GetElementById("email").SetAttribute("value", textbox1.Text)
WebBrowser1.Document.GetElementById("password").SetAttribute("value", pass.Text)
Dim allelements As HtmlElementCollection = WebBrowser1.Document.All
For Each webpageelement As HtmlElement In allelements
If webpageelement.GetAttribute("type") = "submit" Then
webpageelement.InvokeMember("click")
End If
Next
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
WebBrowser1.Navigate("http://adnooka.com/login")
End Sub
You can invoke a submit on the form itself, you don't have to find a button to click.
This should work, if you have only one form on the page. If not, adjust the [0] to whatever is needed:
WebBrowser1.Document.Forms[0].InvokeMember("submit")
See http://msdn.microsoft.com/en-us/library/system.windows.forms.htmldocument.forms.aspx for more details.
I'm trying to fill in my username and password on a certain web page and then the press the "sign-in" button, all automatically via Powershell.
The problem is that I cannot find the ID of the sign-in button in the html source code.
I have tried to use the command:
$link = $ie.Document.getElementsByTagName('A') | where-object {$_.innerText -match 'sign in'}
but this didn't worked either.
Any thoughts which PS command to use if I want to press the 'sign in' button?
The HTML code is as follows:
<div class="login">
<div class="content">
<div class="subsection-1">Sign in or create a <a id="ctl00_HeaderUserControl_LoginUserControl_hypNewAccount" href="/authentication/registerprovider.aspx?">new account</a></div>
<div class="subsection-2">
<span class="navy bold">What is your email address?</span>
<div class="indent">
<span class="bold">Email:</span>
<input id="loginEmail" class="text-box" type="text" maxlength="100" tabindex="1" />
<img class="ajax-loader" src="/content/images/research/global/transparent.gif" alt="" />
</div>
<div class="invalid-email"></div>
</div>
<div class="subsection-3">
<span class="navy bold">Do you know your password?</span>
<div>
<input id="passwordNotKnown" name="passwordSwitch" type="radio" checked="checked" />
<label for="noPassword">No, I don't know my password or I'm new .</label>
</div>
<div>
<input id="passwordKnown" name="passwordSwitch" type="radio" />
<label for="noPassword">Yes, my password is:</label>
<input id="loginPassword" class="text-box" type="password" maxlength="50" tabindex="2" />
</div>
<div class="invalid-password"></div>
<div class="error"></div>
</div>
<div class="subsection-4">
<button type="button" class="login-button greenButton" tabindex="4">Sign in</button>
Cancel
<input id="stayLoggedIn" type="checkbox" tabindex="3" />
<label for="stayLoggedIn">Stay signed in</label>
</div>
</div>
<div class="reset-password">
<div class="subsection-1">Would you like to reset your password?</div>
<div class="subsection-2">Choosing <span class="bold">yes</span> will reset your password and email a temporary password to: <span class="repeat-email"></span></div>
<div class="subsection-3">
<div class="center">
<button class="reset-password-button" type="button">Yes</button>
<button class="do-not-reset-password-button" type="button">No</button>
</div>
</div>
</div>
</div>
I came here looking for a similar answer and figured out how to get this done. Posting here for any future searchers. As noted by Szymon, getElementsByClassName returns an array, and you will need to select the item you need before the click. In my case the classname was button and I was able to click it using the following:
$submitButton = $doc.documentElement.getElementsByClassName('button') | Select-Object -First 1
$submitButton.click()
This works for me because there is only the one item with the classname button, so your results my vary if you have more than one with the same name. Just change what you grab using select-object if need be.
As #Jamie-Taylor mentioned the login button is in fact a button.
You can access it not only by the id but also by the class name using document.documentElement.getElementsByClassName. Please notice this function will return list of elements as more than one element on page can have the same class.
EDIT
I was wrong: in order to have getElementsByClassName you have to call it on document.documentElement instead of document