I need to create a form that will allow users to update a simple text file and then be able to save it in the same location on the server. I can't use PHP (company policy). Is there any way to do this with client-side scripting? My server side scripting is severely restricted. To clarify I just need the contents of an "alert.txt" file to be updated by a user form.
<form>
<div class="form-group">
<label for="alert">Post an Alert</label>
<input type="text" class="form-control" id="alert" placeholder="Enter alert here">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
Related
So I have a registration table in my website that has fields that need to be filled before submission. As far as I know, I have two options to make sure of that. First one is to use the 'required' attribute for each input or to check them at PHP level and using js. Which one is the better practice? Is there a better way to do it? And why?
Here is the way that I do it using HTML:
<form role="form" action="registration.php" method="post" id="login-form" autocomplete="off">
<div class="form-group">
<label for="username" class="sr-only">username*</label>
<input type="text" name="username" id="username" class="form-control" placeholder="Enter Desired Username" required>
</div>
<div class="form-group">
<label for="email" class="sr-only">Email*</label>
<input type="email" name="email" id="email" class="form-control" placeholder="somebody#example.com" required>
</div>
<div class="form-group">
<label for="password" class="sr-only">Password*</label>
<input type="password" name="password" id="key" class="form-control" placeholder="Password" required>
</div>
<input type="submit" name="submit" id="btn-login" class="btn btn-custom btn-lg btn-block" value="Register">
</form>
In the PHP/JS version the code should look like this:
if (empty($username) || empty($email) || empty($password)){
echo "<script>alert('Fields cannot be empty')</script>";
}
I appreciate your help.
My suggestions is to have both, client & server side validation. That way you reduce server load & it's good if you later turn it into the API for eg. Hope this helps.
Client-side validation is the faster way to deal with the validation process than on the server-side because all the tasks happens on the webpage there itself and the network time form client to server is saved.
But in only doing client-side validation there is a risk of attacks clients which can easily bypass the client-side so here it is need to validate the strings submitted by the cilent on the server-side which will save your data from the dangerous inputs.
Note : In short, in terms of faster validation client-side is better and in terms of the security of the data server-side is a better option.
The truth is the server is always out a limitation on every website so as all we can we have to reduce the computing and programs from server to Client-side and to lend the render to user's computer. so if you can use js to do that never interfere PHP on this. just use js and if your problem is going to handle with pure CSS too is going to be very better.
I want to submit a form with a file programmatically but i learned there is no way to pass file to input type="file" because of security. So i am searching a way to submit form with file from url. Html is below.
<form class="converter-form" id="iri-converter-form">
<label for="iri-converter-input">Custom Ontology:</label>
<input type="text" id="iri-converter-input" placeholder="Enter ontology IRI">
<button type="submit" id="iri-converter-button" disabled>Visualize</button>
</form>
<div class="converter-form">
<input class="hidden" type="file" id="file-converter-input" autocomplete="off">
<label class="truncate" id="file-converter-label" for="file-converter-input">Select ontology file</label>
<button type="submit" id="file-converter-button" disabled>
Upload
</button>
</div>
You'll just want to pass the URL to the server. When the server receives the url, it will download the file to disk.
On the HTML/ javascript side of things, you'll probably want to show the Upload File input but give a button to upload from url. When they click that button, hide the upload file button and show a plain textbox for them to drop their url.
You may also want to check that the url is valid: Check if a Javascript string is a url
Also, make sure that the file type is one that you accept, there is always the possibility of malicious code being uploaded and run on the server
I'm stuck here. I want a button (in this case; the Send-email button) to trigger mailto without opening an email client, I want it to automatically send (in JS, smtp) . I don't know if I asked too much and if this is even possible.. This is my form:
<form id="form">
<div class="row">
<div class="col-md-6">
<div class="input-group">
<span class="input-group-addon" id="basic-addon1"><i class="fa fa-user-secret fa-lg"></i></span>
<input id="username" type="text" class="form-control blender-pro-book form-text" placeholder="Username" aria-describedby="basic-addon1">
<span class="input-group-addon" id="basic-addon1"><i class="fa fa-user-secret fa-lg"></i></span>
<input id="message" type="text" class="form-control blender-pro-book form-text" placeholder="Message" aria-describedby="basic-addon1">
</div>
<p class="error-holder"><span id="error" class="error blender-pro-book"><i class="fa fa-exclamation-triangle"></i>Try again please!</span></p>
</div>
</div>
<br>
<div class="row">
<div class="col-md-6 col-md-offset-3 col-xs-10 col-xs-offset-1 col-sm-6 col-sm-offset-3">
<button id="start" type="button" class="btn btn-default btn-lg btn-block btn-custom blender-pro-book">Send e-mail <i class="fa fa-hand-o-right blue-text-color"></i></button>
</div>
</div>
</form>
I've tried putting in several codes but they all result in opening an email client. Then, I discovered SmtpJS.com. I have put the script code in my index file, but I have no clue where to put this code:
Email.send("from#you.com",
"to#them.com",
"This is a subject",
"this is the body",
"mx1.hostinger.nl", */ That's my hosting SMTP /*
"username",
"password");
I just want this button to send an email:
<button id="start" type="button" class="btn btn-default btn-lg btn-block btn-custom blender-pro-book">Send e-mail <i class="fa fa-hand-o-right blue-text-color"></i></button>
Can you please tell me where to put it in my form?
Thank you a lot!
#Ty Q.'s answer is the best approach, but after reviewing SmtpJS, this is how you'd use it:
<html>
<head>
</head>
<body>
<form id="form">
<!--form goes here-->
<input type="submit" value="Submit" />
</form>
<script src="http://smtpjs.com/smtp.js"></script>
<script>
function sendMail(e){
event.preventDefault();
console.log('This will send the mail through SmtpJS');
Email.send("from#you.com",
"to#them.com",
"This is a subject",
"this is the body",
"smtp.yourisp.com",
"username",
"password");
}
function init(){
document.getElementById('form').onsubmit = sendMail;
}
window.onload = init;
</script>
</body>
</html>
Why use some JavaScript Emailing service? Just use PHP.
PHP is a server-sided language. Using commands like $To = $_POST['to']; and $From = $_POST['from'];, you can acquire data sent from a form element.
I recommend you read the PHP manual on the Mail function in order to learn how to send an e-mail using PHP. PHP Mail function It's quite simple actually. If you don't know much of PHP, just go to W3Schools.com's PHP tutorials.
<form method="POST" action="mymail.php">
<input name="to" type="text" placeholder="To:" value="" />
<input name="from" type="text" placeholder="From:" value="" />
<input name="cc" type="text" placeholder="CC:" value="" />
<!-- Blah Blah Blah, your code goes here, I'm not very good at this site -->
<input type="submit" value="Submit" />
</form>
In the above code, it uses a form element with the attributes method and action. Method tells the client that it's going to run in POST, or the more secure version of GET. GET can be seen in a URL like this: https://mywebsite.co/index.php?input=Hi
Unlike GET, POST cannot be seen in the URL, thus it is harder to interfere with. In other words, POST is safer to use. Action represents the file the data is going to be sent to. The server will process the data and it will interpret it into the code (if provided). INPUT tags must have a "name" in order for them to be receivable by the server. The "type" represents whether the INPUT will be just regular "text", a "password", or a "submit". Submit is a button which'll tell the form to send the data when clicked. Placeholder is an input attribute for TEXT and PASSWORD which will show the specified input when the value is null. Value is the attribute which basically contains the parts you want the server to receive. Except for the button, SUBMIT. The value for the SUBMIT button is just the text the button will show. You do not gather data from the button itself.
I have a simple form on my website where it ask the user for their email and the city they're located in like this:
I'm using EmailJS (emailjs.com) and MailJet (mailjet.com) services and while EmailJS and MailJet are doing their jobs, I'm ultimately not able to view the actual form data such as the email and city that was enter anywhere on MailJet, EmailJS or emails that are sent to me. I'm new to web development.
Here's my html code:
<form class="form-inline" type="text" onsubmit="emailjs.sendForm('mailjet', 'myTempNameFromEmailJS', this); return true;" method="get">
<div class="form-group">
<input type="email" class="contactUsEmail" placeholder="Enter email">
</div>
<div class="form-group">
<input type="password" class="contactUsEmail" placeholder="City">
</div>
<button type="submit" class="btn btn-primary contactUsButton">Signup</button>
</form>
What in the world am I doing wrong? I've essentially been working on this since yesterday and can't figure out what I'm doing wrong.
According to the emailjs docs at https://www.emailjs.com/docs/api-reference/emailjs-sendform/ the third parameter of the sendForm method should be "form_id", the id of the form used to collect the parameters. Currently you're sending "this", but that's the variable which (in that particular context) holds the JavaScript representation of the whole form element.
I think you should change it to this.id:
emailjs.sendForm('mailjet', 'myTempNameFromEmailJS', this.id);
Im not familiar with mail jet, however, usually to gain the values out of your forms you need to add the name attribute, for example
<input type="email" class="contactUsEmail" placeholder="Enter email" name="contactUsEmail"/>
name="contactUsEmail"/>
I have a Coming soon page and have a countdown to beta launch and a field where user can enter their email to be added to a mailing list for the beta launch.
How do I receive the email from the field and email myself the user's email upon submit?
Is there a third party service I can use for this? And javascript or jquery plugin?
This is the form with no javascript:
<form class="form-inline" role="form">
<div class="form-group">
<label class="sr-only" for="exampleInputEmail2">Email address</label>
<input type="email" class="form-control transparent" placeholder="Your email">
</div>
<button type="submit" class="btn btn-warning btn-fill">Notify Me</button>
</form>
You have to write backed code with whatever you have on server if it is PHP you could store data from form in file or send it to mail.
Form guide with better description of your problem