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.
Related
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.
I found a lot of these on the side but I don't understand them. Can someone just post the good code and point the wrong things out.
Code didn't want to be posted here is a foto of it
html form
php action
If it helps iam using byethost so I could be something byethost related
Your post indexing is wrong. You can not use value of id attrbute with POST. You have to use value of name attribute so change your code to
$_POST['firstname'] AND $_POST['lastname']
A few things: 1. form should be specified method.
<div>
<form action="login_action.php" method="post" >
<label for="fname">First Name</label>
<input type="text" id="fname" name="firstname" >
<label for="lname">Last Name</label>
<input type="text" id="lname" name="lastname" >
</div>
otherwise, the form will be using get method, and there is no data send to $_POST. refer to http://www.w3schools.com/tags/att_form_method.asp
As #User7 mentioned. The data index in $_POST is based on the input name, not id
$sql ='INSERT INTO login_info(fname, lname) VALUES ("'.$_POST['firstname'].'","'.$_POST['lasttname'].'")';
if(!mysql_query($sql, $con)){
die('error:'.mysql_error());
}
I'm trying to create a contact form on my own. I noticed that it can be achieved by placing the form inside an article, instead of a custom html module.
In the client side, it seems to work. I even added a captcha manually (the re-captcha plugin doesn't seem to work for me). The problem is, I set form's action property as "mail.php", and just added this "mail.php" file to the the template root. The "mail.php" supossedly retrieves the data send by post, and finally composes and sends the email, showing a "message send" notification.
Anyway, when I click on submit, the form page is just reloaded. I guess that Joomla! can't find my "mail.php". I guess that this issue is related to the joomla structure and my inability to place the "mail.php". Any help will be wellcome.
This is how my article looks like (wysiwyg editor mode disabled):
<form action="mail.php" method="post" target="_blank">
<p><label for="nombre">Nombre:</label></p>
<p><input maxlength="50" name="nombre" size="30" type="text" /></p>
<p><label for="email">Email:</label></p>
<p><input maxlength="50" name="email" required="required" size="30" type="text" /></p>
<p><label for="asunto">Asunto:</label></p>
<p><input maxlength="150" name="asunto" size="30" type="text" /></p>
<p><label for="mensaje">Mensaje:</label></p>
<p><textarea cols="50" maxlength="700" name="mensaje" required="required" rows="8"></textarea></p>
<div class="g-recaptcha" data-sitekey="6Lefblahblahblahblah"> </div>
<p><input type="submit" /></p>
</form>
I have a form on my site that gets submitted to a third party site which basically adds the form data as a record in the third party database. This is implemented with the form "action" attribute. I have no control over what the third party does after the form is submitted. See below for the implementation.
I'm doing javascript validation, but I also need to be able to do server-side sanitation and validation of the form data with php before it gets sent to the third party. I may also want to implement a CAPTCHA.
What approach can I take to achieve this? I thought about having the form submit to the script that houses the form, and collecting all of my $_POST variables, do the validation, and then maybe redirect to the third party URL, but not quite sure how the third party would receive all the form data if its not longer the form action. Is it possible to just tack all of my form variables on as a query string the third party URL?
<form id="contactform" name="contactform" onsubmit="return validateForm(this)" method="post" encType="multipart/form-data" action="https://thirdpartysite.com/db/?action=AddRecord&apptoken=xxx">
<input class="contactfield required contact_name_first" type="text" id="firstname" name="firstname" placeholder="FIRST NAME" />
<input class="contactfield required contact_name_last" type="text" id="lastname" name="lastname" placeholder="LAST NAME" />
<input class="contactfield required contact_org" type="text" id="organization" name="organization" placeholder="ORGANIZATION" />
<input class="contactfield required contact_email" type="text" id="email" name="email" placeholder="EMAIL" />
<input class="contactfield required contact_phone" type="text" id="phone" name="phone" placeholder="PHONE" />
<textarea class="contactfield required contact_msg" id="message" name="message" cols="40" rows="10" placeholder="HOW CAN WE HELP YOU?"></textarea>
<input type="hidden" name="rdr" value="http://www.mysite.com/thank-you" /><!-- Note: this gets passed to the third party site as the page to redirect back to after third party site receives the form data" -->
</form>
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.