How to make a working Submit button on HTML? [duplicate] - php

This question already has answers here:
Send email with PHP from html form on submit with the same script
(8 answers)
Closed 5 years ago.
The question is how do i make the submit button work so if they press submit, the ff will be send to my email (ex: example#gmail.com).'
If PHP is needed please post the code so i just gonna paste it on my code :D ty
<div id="forms">
<form class="form">
<p class="name">
<input type="text" name="name" id="name" placeholder="Enter Your Name" />
</p>
<p class="email">
<input type="text" name="email" id="email" placeholder="mail#example.com" />
</p>
<p class="text">
<textarea name="text" placeholder="Describe your logo" /></textarea>
</p>
<p class="submit">
<input type="submit" value="Send" />
</p>
</form>
</div>
I cannot find the answer in the existing question of this, So i decided to make another one... the existing is like 2 years ago?

I think you just need to put a mailto action on the <form> tag, i.e.:
<form class="form" action="mailto:someone#example.com">

All you need to do is change your form tag to look like this:
<form action="mailto:address#example.com">
This will send unformatted data to your email address without needing PHP. If you would rather format it in a specific way, then you can use the PHP mail function.
I also removed class="form". Typically this is not needed, but it depends on your reason. If you are using class for CSS you can just reference the element form rather than the class name .form.

Related

PHP form needs be sumbited 2 times to get post [duplicate]

This question already has answers here:
Checking if form has been submitted - PHP
(9 answers)
Closed 12 months ago.
I'm novice and i want save images from a Form in php.
my code is pretty simple:
<form method="POST" enctype="multipart/form-data" action="">
<label for="nom">Nom :</label><input type="text" name="nom" id="nom">
<label for="adresse">Adresse :</label><input type="text" name="adresse" id="adresse">
<label for="tel">Numéro de télephone :</label><input type="text" name="tel" id="tel">
<label for="mail">E-mail :</label><input type="text" name="mail" id="mail">
<label for="web">Url du site web</label><input type="text" name="web" id="web">
<label for="images">Logo/image</label>
<input type="file" multiple name="images" id="images" />
<input type="submit" class="bouton" id="valider" value="valider"/>
</form>
and I just want see if my images arrive in my $_FILES.
so i have at the top of my index.php
<?php
echo var_dump($_FILES);
?>
when i press the submit button the 1st time, it's still empty, but if i press it a second time, i get it.
do someone knows why ?
thank you.
The first click is putting you on the webpage of the form as it
can't work without fields populated.
The second click is running your action with files inside it, so
it works.
Why ?
Because you are displaying your form in various webpages, you must handle your form action in a website global point of view. You are using php so try to use the layout feature for html is one thing, but do not forget to do the same for handling your POST action globally.

PHP action $_SERVER['PHP_SELF'] resuts in error 404 [duplicate]

This question already has answers here:
PHP code is not being executed, but the code shows in the browser source code
(35 answers)
Closed 4 years ago.
I am new to PHP and I am trying to make a contact us form that will perform validation and will display an error if any of the fields are not entered correctly.
I tried following this tutorial W3schools php example
so this is how my form looks like
<h2>PHP Form Validation Example</h2>
<p><span class="error">* required field.</span></p>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
Name: <input type="text" name="name">
<span class="error">* <?php echo $nameErr;?></span>
<br><br>
E-mail: <input type="text" name="email">
<span class="error">* <?php echo $emailErr;?></span>
<br><br>
Website: <input type="text" name="website">
<span class="error"><?php echo $websiteErr;?></span>
<br><br>
Comment: <textarea name="comment" rows="5" cols="40"></textarea>
<br><br>
Gender:
<input type="radio" name="gender" value="female">Female
<input type="radio" name="gender" value="male">Male
<span class="error">* <?php echo $genderErr;?></span>
<br><br>
<input type="submit" name="submit" value="Submit">
</form>
but I get an error saying
Error 404 - Not Found
The document you are looking for may have been removed or re-named.
Please contact the web site owner for further assistance.
and my url changes to this
my domain name/%3C?php%20echo%20htmlspecialchars($_SERVER[
what am I doing wrong here? Also if this is not the right approach, can someone make a suggestion how can I display the error messages and success messages after validating and sending the email via PHP?
Update:
Ok, so first of all, the problem was the file extension so thank you Chris for your helpful comment. If you want, add your comment as an answer and I will select it as a correct answer.
Second. I had a problem when upon changing the extension and my href attributes, the server was still taking me to contactUS.html page instead of contactUs.php page. The problem was that my links were generated in JavaScript and for some reason, my browser was not using the updated javaScript files. I solved this by clearing my cookies.
Use double quotes arround php tag and single quotes for $_SERVER key. Like use below example then it will work for you.
<form method="post" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" >

PHP and my current HTML w/ CSS files [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
This question will more than likely result in an easy answer, however I am at a roadblock until hopefully someone can help, as I am new to PHP.
So I had a basic registration page in HTML and styled in CSS for my website, however it obviously did nothing. So I acquired the necessary PHP files to make it all work, and tested the PHP on a localserver and it was excellent as anticipated.
However my question is, how can I bring the functionality of the PHP into my already created SignUp.html page?
Or do I need to somehow style the PHP and scrap my current html and css files?
I'll attach my current basic html code in the event that helps.
<h2>Sign Up</h2>
<div id="form-data">
<fieldset>
<div class="fieldgroup">
<label for="name"> Username</label>
<input type="text" name="name">
</div>
<div class="fieldgroup">
<label for="name">First Name</label>
<input type="text" name="name">
</div>
<div class="fieldgroup">
<label for="name">Last Name</label>
<input type="text" name="name">
</div>
<div class="fieldgroup">
<label for="email">Email</label>
<input type="text" name="email">
</div>
<div class="fieldgroup">
<label for="password">Password</label>
<input type="password" name="password">
</div>
<div class="fieldgroup">
<p class="right">By clicking register you agree to our <a target="_blank" href="#">policy</a>.</p>
<input type="submit" value="Sign up" class="submit">
</div>
</fieldset>
</div>
Rename the .html file to the .php extension and then put the PHP code into it.
Probably something like:
if(isset($_POST['sent']))
{
// PROCESS FORM IN PHP HERE
}
will help you when modifying the submit button to:
<input type="submit" name="sent" value="Sign up" class="submit">
You can change the extension of the .html files to .php to bring the functionality of PHP to your files. The HTML will still be treated as HTML, so there is no need to change the HTML markup if you change the extension.
You can also "instruct Apache to treat .html as PHP." as #Fred-ii- said.
For running the form through PHP, you can either direct the form to a .PHP file like so:
<form action="phpfile.php" method="*post OR get*">
or you can run it on the page the form is on like so:
<form action="" method="*post OR get*">
<!-- Form Contents Here -->
</form>
<?php
if(isset($_POST['submit'])) {
// PHP code here
}
?>

PHP form client side validation [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to determine if user selected a file for file upload?
I would like a simple PHP form validation. My form has two inputs: A link and a file to upload. The form should be submitted only if the link field is filled and the user selected a file to upload. If one of them is or both are false, an alert box should be displayed (like here when you click Upload without selecting a file).
This is my form:
<form action="upload_file.php" enctype="multipart/form-data" method="post">
<p>Link:<br>
<input type="text" name="link" size="50">
</p>
<p>Image:<br>
<input type="hidden" name="MAX_FILE_SIZE" value="2000000">
<input type="file" name="file" id="file" size="40">
</p>
<div>
<input type="submit" name="upload" value="Upload">
</div>
</form>
I am new to PHP and I have been browsing tutorials for hours now, many of them was of no help or shows the server side validation.
I understand I should start with this:
<form method="POST" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
to validate the fields before the form is submitted. I have some basic knowledge of PHP but I cannot figure out how to do this easy or not so easy task.
php is server side. What you need is a client side checker (js, jq ..)
You can perform the check only with php, but on your server, then return to the client the error message or the task complete message. If you want the check to be done client side, you need a client side language to handle it.
PHP is indeed a server-side application and thus cannot perform client-side validation.
If you really want to do client-side validation, you'll probably have to use javascript. Have a look at the jQuery validation plugin. Here is a big demo page showing you some of the possibilities: http://jquery.bassistance.de/validate/demo/
For more help and information, also have a look at the jQuery.com/plugins/validation page.
(Note the WARNING at the end of this post)
Example:
(the javascript)
<script>
$(document).ready(function(){
$("#commentForm").validate();
});
</script>
(the form)
<form class="cmxform" id="commentForm" method="get" action="">
<fieldset>
<legend>A simple comment form with submit validation and default messages</legend>
<p>
<label for="cname">Name</label>
<em>*</em><input id="cname" name="name" size="25" class="required" minlength="2" />
</p>
<p>
<label for="cemail">E-Mail</label>
<em>*</em><input id="cemail" name="email" size="25" class="required email" />
</p>
<p>
<label for="curl">URL</label>
<em> </em><input id="curl" name="url" size="25" class="url" value="" />
</p>
<p>
<label for="ccomment">Your comment</label>
<em>*</em><textarea id="ccomment" name="comment" cols="22" class="required"></textarea>
</p>
<p>
<input class="submit" type="submit" value="Submit"/>
</p>
</fieldset>
</form>
WARNING
Please keep in mind that javascript, being client-side, runs on the client's computer. Don't rely on javascript validation alone. Anyone can disable javascript and insert 'wrong' values in your form.
In case of form it's best to do client side validation using some javascript library like jQuery. Check out this jQuery tool for form validation.
For server side validation, check out this link. It may help you.
Validation should be done on server side ALWAYS. You can add client minor validation also as a confort for the user with javascript.
Here some basic code to show a message if fields empty using minor validation:
<input type="submit" name="upload" value="Upload" onclick="var ref = document.getElementById('file'); if ( ref.length == 0 ){ alert( 'select file' ); return false; } ref = document.getElementById( 'textfieldid' ); if ( ref.value.length == 0 ){ alert( 'fill link, better use a regexp to match a url but this another store' ); return false; }">
For client side validation of "File upload" field, refer following plug-in :
http://adamsanderson.github.com/jQuery-File-Validator/
It is useful. I have tried it.

Email contact form without PHP

I'd like to use a contact form for a website I'm creating, but PHP is not an option since the client doesn't wish to use it. Is there a clever way to work around this somehow, by sending email parameters (which is non-standard) perhaps, or by using an external contact form? Are there any good ones that don't use advertising and are easily modified to a different language for example?
Thank you.
Check out formspree.
https://github.com/asm-products/formspree
For action you simply put:
<form action="http://formspree.io/you#email.com" method="post">
<input type="text" name="name">
<input type="email" name="_replyto">
<input type="submit" value="Send">
After verifying your email after the first send this will email you the contents of the form. One thing to keep in mind is that this will take the input names. If you do not include input names it won't send you that form field.
There are hundreds of embeddable (most likely iframe-based) solutions for contact forms, which would enable you to get around using a server-side language like PHP. Just a quick google search will give you some.
Alternatively, you could make a form in HTML, and have a submit button which is actually a mailto: link, and you modify the parameters of that mailto as your form inputs change.
The only downside of this is that it's not as convenient for the user, as it then opens up their email client and they have to actually send it.
Personally, I would try and persuade the client, but if that isn't possible, then those are your options.
Check out www.enformed.io.
Has a couple of interesting options that formspree does not have( Like redirect out of the box, and a html email editor).
I used Formspree but formspree doesn't allow ajax unless you have Gold Version. It doesn't work on the basic so I am planning on making an account on enformed.io. I still haven't used it but I have heard that t is very good. You can also use alerts fro success and error messages.
<form style="margin-left: 6%;" class="email" action="https://www.enformed.io/YOUR_TOKEN" method="post">
<p>Name:</p>
<input type="text" name="first_name" />
<div id="margin" style="height: 0.5%;"></div>
<p>E-mail:</p>
<div id="margin" style="height: 0.5%;"></div>
<input type="text" name="email" />
<div id="margin" style="height: 0.5%;"></div>
<p>Subject:</p>
<div id="margin" style="height: 0.5%;"></div>
<input type="text" name="subject" />
<div id="margin" style="height: 0.5%;"></div>
<p>Message:</p>
<div id="margin" style="height: 0.5%;"></div>
<textarea name="message"></textarea>
<div id="margin" style="height: 0.5%;"></div>
<button type="submit" class="btn btn-default">Submit Form</button>
</form>
Would something as simple as a mailto form work?

Categories