I am writing a page where a user can fill out form data, select two files for upload, and then hit Submit to pass the form data into the PHP page, and also the two files will be uploaded.
The problem is the submit button seems to be able to only be either a 'submit' or a 'File_Upload'. It can't do both... or can it?
Here is the gyst of HTML file (Just enough to get the point across... I hope)
<form class='form' name="frm_new_session" method="POST" enctype="multipart/form-data">
<div class='frm_row'>
<label>Title</label>
<input id="titleF" type='text' name="title" size='50' />
<input type="hidden" name="_chkuser" value="1"/>
</div>
<div class='frm_row'>
<label>Description</label>
<textarea id="descF" rows='3' cols='53' name="desc"></textarea>
</div>
<div class='frm_row'>
<label>Image</label>
<input id="imageF" type="file" name="uploadedimage">
<input type="hidden" name=MAX_FILE_SIZE" value='50000000'/>
</input> <br />
</div>
<div class='frm_row'>
<label>Session Media</label>
<input type='radio' id="mediaF" name="media" />
Upload: <input type='file' name="fileupload">
</input> <br />
<input type='radio' id="mediaF" name="media" />
Enter media URL:
<input type='text' size='75' name="mediaFile"/>
</input>
</div>
<div class='frm_row'>
<input type="submit" value="Save Session"/>
<div class='btn' type="submit" style='float: left;'>
<a href='#' id='btn_save_session'><span>Save Session</span></a>
<div class='kill_clear'></div>
</div>
</form>
I know I can do this using multiple forms, but I would like to avoid that and enjoy having just a single 'Save' button.
Any suggestions?
i don't understand the problem, the info will be in the $_POST array and the files in the $_FILES array.
however, you are missing a double quote in MAX_FILE_SIZE, i tested the following code, and it works :D
<?php
print_r($_POST);
print_r($_FILES);
?>
<form class='form' name="frm_new_session" method="POST" enctype="multipart/form-data">
<div class='frm_row'>
<label>Title</label>
<input id="titleF" type='text' name="title" size='50' />
<input type="hidden" name="_chkuser" value="1"/>
</div>
<div class='frm_row'>
<label>Description</label>
<textarea id="descF" rows='3' cols='53' name="desc"></textarea>
</div>
<div class='frm_row'>
<label>Image</label>
<input id="imageF" type="file" name="uploadedimage">
<input type="hidden" name="MAX_FILE_SIZE" value='50000000'/>
</input> <br />
</div>
<div class='frm_row'>
<label>Session Media</label>
<input type='radio' id="mediaF" name="media" />
Upload: <input type='file' name="fileupload">
</input> <br />
<input type='radio' id="mediaF" name="media" />
Enter media URL:
<input type='text' size='75' name="mediaFile"/>
</input>
</div>
<div class='frm_row'>
<input type="submit" value="Save Session"/>
<div class='btn' type="submit" style='float: left;'>
<a href='#' id='btn_save_session'><span>Save Session</span></a>
<div class='kill_clear'></div>
</div>
</form>
<form action="/add-news.php" method="post" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="5242880" />
<input type="text" name="title" />
<input type="file" name="image" />
<textarea rows="40" cols="50" name="content"></textarea>
</form>
Try adding hidden field MAX_FILE_SIZE where value is max size of files in bytes.
It works for me.
What you mean by: "It can't do both", what are the indications?
Related
If I add the first div inside the form, the submit button stops working. Must be somehow related to the nested 'post' calls and the different .php files.
<form action="register.php" method="post">
<div id="kv-avatar-errors-1" class="center-block" style="width:800px;display:none"></div>
<form class="text-center" action="/avatar_upload.php" method="post" enctype="multipart/form-data">
<div class="kv-avatar center-block" style="width:200px;text-align:center;">
<input id="avatar-1" name="profile_pic" type="file" value="" class="file-loading">
</div>
</form>
</div>
<label>Username:</label>
<input type="text" name="username" value="" />
<label>Email:</label>
<input type="text" name="email" value="" />
<label>Password:</label>
<input type="password" name="password" value="" /> <br /><br />
<input type="submit" class="btn btn-info" value="Register" />
</form>
What's the best way to fix this?
Cause form inside form is an invalid syntax. – u_mulder
I'm trying to call a php file in a html form, as shown in my code, but the send button is not functioning, any ideas ?
<form id="contact-form" method="post" action="form_send.php">
<fieldset>
<label class="name">
<input type="text" value="Your Name" onFocus="if(this.value=='Your Name'){this.value=''}" onBlur="if(this.value==''){this.value='Your Name'}">
</label>
<label class="phone">
<input type="text" value="Telephone" onFocus="if(this.value=='Telephone'){this.value=''}" onBlur="if(this.value==''){this.value='Telephone'}">
</label>
<label class="email">
<input type="email" value="Email" onFocus="if(this.value=='Email'){this.value=''}" onBlur="if(this.value==''){this.value='Email'}">
</label>
<label class="message">
<textarea onFocus="if(this.value=='Message'){this.value=''}" onBlur="if(this.value==''){this.value='Message'}">Message</textarea>
</label>
<div class="btns"> <a class="button" onclick="clearFunction()" >Clear</a> <a class="button" type="submit" name="submit" value="Send Form" >Send</a> </div>
</fieldset>
</form>
you are use <a> tag to submit the form
replace <a class="button" type="submit" name="submit" value="Send Form" >Send</a> with <input class="button" type="submit" name="submit" value="Send Form" >
You are not naming any inputs in your form..
<input **name='name'** value='Your name'>
<input **name='phone'** value='Phone'>
and so on..
for proccessing:
if(isset($_POST['submit'])){
$name=$_POST['name'];
$phone=$_POST['phone'];
$xxx=$_POST['xxx'];
echo $name, $phone; //echoing data.
}
and so on.
Don't forget to sanitize your data before submitting..(ANTI-SQL INJECTION)
and instead of your OnBlur and OnFocus solution: placeholder='Your name'
Somehow when I submit this form the values are stored last name then first name. How can I change the order?
<form action="..posted" method="post" id="register-form">
<div class=register-form-div>
First Name: <input class=register-form-input type="text" name="register[First name]" />
</div>
<div class=register-form-div>
Last Name: <input class=register-form-input type="text" name="register[Last Name]" />
</div>
<input type="submit" id="register-submit" name="register-submit" value="Create Account" />
</form>
try that
<form action="..posted" method="post" id="register-form">
<div class=register-form-div>
First Name: <input class=register-form-input type="text" name="register[1][First name]" />
</div>
<div class=register-form-div>
Last Name: <input class=register-form-input type="text" name="register[0][Last Name]" />
</div>
<input type="submit" id="register-submit" name="register-submit" value="Create Account" />
</form>
I have a GET form at the top of my page, but it is not yet configured. All I have for it is this:
<div class="top-search">
<form method="get" id="searchform" action="#">
<div>
<input type="text" value="Search..." name="s" id="s" onfocus="defaultInput(this)" onblur="clearInput(this)" />
<input type="submit" id="searchsubmit" value=" " />
</div>
</form>
</div>
How can I manipulate this to use Google CSE?
Seeming as no one decided to answer it, I found out for myself.
<div class="top-search">
<form id="searchform" action="http://www.google.com/cse">
<div>
<input type="hidden" name="cx" value="xxxx" />
<input type="hidden" name="ie" value="UTF-8" />
<input type="text" value="" name="q" id="q" autocomplete="off" />
<input type="submit" id="searchsubmit" name="sa" value=" " />
</div>
</form>
</div>
Where "xxxx" is your Search Engine Unique ID, found on the Basics page of your control panel.
I use the farbtastic color picker, I included all files for this, but how can I call this color picker when I double click?
More info:
That's my placeholder in my .tpl file. and I call it as follow.
// color picker selecteren.
$(function(){
$("#color").dbclick(function(){
$('#colorpicker').farbtastic('#color');
});
});
<!-- new color form -->
<form action="controller.php" method="post" class="popupform" id="form_changecolor">
<div id="colorpicker"></div>
<table>
<tr><th>huidige:</th><th>nieuwe:</th></tr>
<tr><td><input type="text" name="oldcolor" disabled="disabled" id="oldcolor" /></td><td><input type="text" name="newcolor" id="newcolor" /></td></tr>
</table>
<div class="buttonrow">
<input type="hidden" name="page" value="{$PAGE}" />
<input type="hidden" name="module" value="changecolor" />
<input type="hidden" name="id" id="parameter_key" value="" />
<input type="submit" class="btnOk" value="Aanpassen" />
<input type="button" class="btnCancel" value="Annuleren" />
</div>
</form>
#NeXXeus, I already try it to do so (too big for a comment, and useful in the context of this question):
That's my placeholder in my .tpl file. and I call it as follow.
// color picker selecteren.
$(function(){
$("#color").dbclick(function(){
$('#colorpicker').farbtastic('#color');
});
});
<!-- new color form -->
<form action="controller.php" method="post" class="popupform" id="form_changecolor">
<div id="colorpicker"></div>
<table>
<tr><th>huidige:</th><th>nieuwe:</th></tr>
<tr><td><input type="text" name="oldcolor" disabled="disabled" id="oldcolor" /></td><td><input type="text" name="newcolor" id="newcolor" /></td></tr>
</table>
<div class="buttonrow">
<input type="hidden" name="page" value="{$PAGE}" />
<input type="hidden" name="module" value="changecolor" />
<input type="hidden" name="id" id="parameter_key" value="" />
<input type="submit" class="btnOk" value="Aanpassen" />
<input type="button" class="btnCancel" value="Annuleren" />
</div>
</form>
You question isn't very clear, this page has a very nice description on setting it up: http://acko.net/dev/farbtastic
Basing off of the example there, if you only want it to become a colorpicker when it is double-clicked...
$("#color").dblclick(function(){
$('#colorpicker').farbtastic('#color');
});