I am trying to store a content of elRTE into the database using PHP,
<script type="text/javascript" charset="utf-8">
// elRTE with elFinder on a textarea
$().ready(function() {
var opts = {
cssClass : 'el-rte',
$('#editor').elrte(opts);
})
</script>
<div id="finder"></div>
<form name="feedback" method="post">
<textarea id="editor" name="acontent" cols="50" rows="4"><?=$abt_content?></textarea>
<input type="submit" name="updabt" value="Submit"></td></tr>
</form>
<?php
if(isset($_POST['updabt']))
{
extract($_POST);
$q1=mysql_query(...);
if($q1==true)
{...}
else
{...}
}
?>
But I always get error "Undefined variable acontent"..
Any solution on this??
<form name="feedback" method="post">
<div id="finder"></div>
<textarea id="editor" name="acontent" cols="50" rows="4"><?=$abt_content?></textarea>
<input type="submit" name="updabt" value="Submit"></td></tr>
</form>
<?php
if(isset($_POST['updabt']))
{
extract($_POST);
$q1=mysql_query(...);
if($q1==true)
{...}
else
{...}
}
?>
Note: for editer you have to use div's id for POST as
$_POST['finder'];
Related
I have a select in my HTML form:
<form name="correo" id="correo" method="post" action="#" enctype="multipart/form-data" onSubmit="<!--return checkFields();-->" ><div class="multi-field-wrapper" name="multi-field-wrapper">
<div class="multi-fields" name="multi-fields">
<div class="multi-field" name="multi-field">
<div>
<label for="penviadas[]"> Cantidad </label>
<input type="number" name="penviadas[]" class="penviadas" id="penviadas" maxlength="70" placeholder="¿Cuántas?" onClick="removerIcon('iconcant');" >
</div>
</div>
</div>
<button type="button" class="add-field">Añadir otra referencia</button>
</div>
And I can add fields dynamically (or what's the same, I can repeat the code above many times; the code below works).
$('.multi-field-wrapper').each(function() {
var $wrapper = $('.multi-fields', this);
$(".add-field", $(this)).click(function(e) {
$('.multi-field:first-child', $wrapper).clone(true).appendTo($wrapper).find('input').val('').focus();
});
$('.multi-field .remove-field', $wrapper).click(function() {
if ($('.multi-field', $wrapper).length > 1)
$(this).parent('.multi-field').remove();
});
});
Let's say I have 3 different selects (penviadas). What I want is to get all of them in my PHP file once I submit the form. It used to work, but now, for some reason, I can only get THE FIRST select (penviadas). Why am I not getting all the values from penviadas array?
PD: I print it in my PHP in different ways but they all return ONLY THE FIRST ELEMENT from penviadas, not the rest:
var_dump($_REQUEST['penviadas']);
I figured it out after many hours playing stupid.
With the information in the OP it was impossible to discover where there was a problem. I found the solution here: Submitting form from different <div> HTML
Basically, I had this structure:
<div...
<form...
</div...
</form>
I thought it was alright and didn't think for a moment this could be affecting. Thus, it wasn't the PHP/JS but the html tags that were incorrect. Thanks for your time.
PHP Code :
<?php
if(isset($_POST['test']))
{
$data = $_POST['referenciasnuevas'];
foreach ($data as $key => $value) {
echo $value . "<br />";
}
}
?>
Html Code:
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
</head>
<body>
<form method="post" action="#">
<div class="multi-field-wrapper" name="multi-field-wrapper">
<div class="multi-fields" name="multi-fields">
<div class="multi-field" name="multi-field">
<label for="referenciasnuevas[]">Referencia pieza</label>
<select name="referenciasnuevas[]" id="referenciasnuevas" class="referenciasnuevas" style="width: 105px" onClick="removerIcon('iconref');">
<option selected value='-1'> ¿cliente? </option></select>
</div>
</div>
<button type="button" class="add-field">Añadir otra referencia</button>
</div>
<input type="submit" name="test" value="Submit">
</form>
<script>
$('.multi-field-wrapper').each(function() {
var $wrapper = $('.multi-fields', this);
$(".add-field", $(this)).click(function(e) {
$('.multi-field:first-child', $wrapper).clone(true).appendTo($wrapper).find('input').val('').focus();
});
$('.multi-field .remove-field', $wrapper).click(function() {
if ($('.multi-field', $wrapper).length > 1)
$(this).parent('.multi-field').remove();
});
});
</script>
</body>
</html>
The above code works for me.please look my code
I have an index.php and output.php
I need two buttons both linked to output.php but to different functions and I can't get it work. Here is my code:
In index.php:
<?php
include 'output.php';
if (isset ($_POST ['choice3'])){
choice3();
}
if (isset ($_POST ['choice4'])){
choice4();
}
?>
<form method="post" action="output.php">
<input type="submit" name="choice3" id="choice3" value="Choice 3">
<input type="submit" name="choice4" id="choice4" value="Choice 4">
</form>
In Output.php,
function choice3(){} and function choice4(){}
Each function have different output.
But now, when I click the button, nothing shows up.
Thanks for help!!
Replace your index.html.php and output.php with this
Index.php
<form method="post" action="output.php">
<input type="submit" name="choice3" id="choice3" value="Choice 3">
<input type="submit" name="choice4" id="choice4" value="Choice 4">
</form>
Output.php
<?php
if (isset ($_POST ['choice3']))
{
/ body of the choice 3 function without the function signature
}
elseif(isset ($_POST ['choice4']))
{
/ body of the choice 4 function without the function signature
}
?>
Just Replace your code with this
<?php
include 'output.php';
$choice = $_POST['choice'];
if ($choice == 'choice3') {
choice3();
} else if ($choice == 'choice4') {
choice4();
}
?>
<script>
function make_choice(choice) {
document.getElementById('choice').value = choice;
document.choice_form.submit();
}
</script>
<form method="post" action="" name="choice_form">
<input type="hidden" name="choice" id="choice" value="" />
<input type="button" name="choice3" id="choice3" value="choice3" onclick="make_choice(this.value);">
<input type="button" name="choice4" id="choice4" value="choice4" onclick="make_choice(this.value);">
</form>
i have a simple website which is written by php and mysql code. i have a detect button on my my sql table query page and given below code is writen for this function but my problem is i need a popup window when the detect link is clicked. i have tired to set a code in my created code but i am not able .kindly please help me solve this problem.
<?php $sezione="home_admin"; if(isset($_POST['messaggio']))
$messaggio=$_POST['messaggio'];
include("control_admin..php");
$canc_id=$_GET['canc_id'];
$idcorsocanc=$_POST['idcorsocanc'];
$action=$_REQUEST['action'];?>
<?php
/*echo "permessi".$permessi;
echo "<br>id".$id_nome;*/
if($action=='canc'){?>
<h1>are you sure want to delect the course?</h1>
<form action="<?=$_SERVER['PHP_SELF']?>" method="post" name="canc1" style="float: left; margin-left:25px;">
<input type="hidden" name="idcorsocanc" value="<?=$canc_id?>">
<input type="hidden" name="action" value="">
<input type="submit" name="ok" value="Si,cancella" class="puls_invia">
</form>
<form action="<?=$_SERVER['PHP_SELF']?>" method="post" name="canc2" style="float: left; margin-left:25px;">
<input type="hidden" name="action" value="">
<input type="submit" name="ok" value="NO" class="puls_invia">
</form>
<?php
}
ok i want to update my question cause i follow one answer and here the code is-
<html>
<head>
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script>
$(document).ready(function() {
$('#ok').click(function(){
if(confirm('Are you sure ?')){
$('#form').submit();
}else{
return false;
}
});
});
</script>
</head>
<body>
<?php
if(isset($_POST['action'])){
if($_POST['action'] == 'deleted'){
//the form has been sent, do something
}
}else{
?>
<form action="<?=$_SERVER['PHP_SELF']?>" method="post" id="form">
<input type="button" id="ok" name="ok" value="Delete">
<input type="hidden" id="action" name="action" value="deleted">
</form>
<? } ?>
</body>
</html>
but till now my problem is i alreday have link name delect and if i click that link i saw another delete button cause now i use the following code which i just update then if i click there i saw the pop up window but if i click ok that course is not delete cause i guess something is missing.
my actual need is i alreday have delect link and i need something that if i click on that i saw one opoup window.just this is my need.
You need a client-side script to manage this. I'd recommend something in jQuery.
<script type="text/javascript">
$(document).ready(function(){
$(".myButton").click(triggerPopup);
})
function triggerPopup(){
//do popup stuff
}
</script>
an example in more details can be found by googling. something like this http://istockphp.com/jquery/creating-popup-div-with-jquery/
You should do this in javascript. Especially with jquery library
This should look like this :
<?php
include("control_admin.php");
$sezione = "home_admin";
$canc_id = $_GET['canc_id']; //i'm gessing this is the ID to delete ?
?>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script>
$(document).ready(function() {
$('#ok').click(function(){
if(confirm('Are you sure ?')){
$('#form').submit();
}else{
return false;
}
});
});
</script>
</head>
<body>
<?
if(isset($_POST['action'])){
if($_POST['action'] == 'deleted'){
$id = $_POST['id'];
$sql = "delete from table_name where column_id = ".$id;
mysql_query($sql);
echo $canc_id . ' has been deleted!';
}
}else{
?>
<form action="<?=$_SERVER['PHP_SELF']?>" method="post" id="form">
<input type="button" id="ok" name="ok" value="Delete">
<input type="hidden" id="action" name="action" value="deleted">
<input type="hidden" id="id" name="id" value="<?=$canc_id?>">
</form>
<? } ?>
</body>
</html>
I'm doing php that is textbox a value empty it will open a alertbox (I'm using javascript in here )
this is my code
<?php
include('config.php');
if(isset($_POST['submit'])){
$username=$_POST['username'];
?>
<script>
function validate(){
if(document.forms[0].username.value==""){
window.alert("You must enter both values");
return false;
}
}
</script>
<?php
}
?>
<html>
<div><p>Member Profile</p>
<form action="testing.php" method="POST" onsubmit="return validate();">
Username<br>
<input class="user" type="text" name="username" id="username" /><br>
<input type="submit" name="submit" value="register" />
</form>
</div>
</html>
The problem is i have to click 2 times before the alert show
please help me to solve this problem
It's because the script is inside the php if(isset){} block, one click submits the form, which generates the script and then it works the second time.. try this setup instead:
<?php
include ('config.php');
if (isset($_POST['submit']))
{
$username = $_POST['username'];
}
?>
<html>
<head>
<script>
function validate () {
if (document.forms[0].username.value == "") {
window.alert("You must enter both values");
return false;
}
}
</script>
</head>
<body>
<div>
<p>
Member Profile
</p>
<form action="testing.php" method="POST" onsubmit="return validate();">
Username
<br>
<input class="user" type="text" name="username" id="username" />
<br>
<input type="submit" name="submit" value="register" />
</form>
</div>
</body>
</html>
Edit:
I've moved the script tag inside the head tag. I'm not sure if there are any implications for having the script outside but just to be sure I've moved it.
2nd Edit: (OCD is kicking in)
I've added body tags, not sure if you copied and pasted this code but it looked weird to me :)
I'm generating a number of textareas with jQuery. I want to retrieve the values of all the filled out textareas via an on-page POST method (it's kind of a proof of concept, quick and dirty, I wouldn't do this normally), but when I hit submit, I get the value of only one, whichever is the last textarea value posted. I imagine I can do this with an array and a foreach loop, but am unsure how to do it, given all the additions of the jQuery/on-page factors complications in this endeavor. I also imagine it might have something to do with all of the generated textareas having the same name... anyone?
Here's the code-
<script type="text/javascript">
$(document).ready(function() {
$('.textadder').click(function(){
$("form").append("<p class='introText2'>Enter More Text</p><textarea rows='5' cols='20' name='textForm' class='formText2'></textarea>");
});
});/*document ready*/
</script>
<?php
if (isset($_POST['textForm']))
{
$formTxt = $_POST['textForm'];
echo $formTxt;
}
?>
</head>
<body>
<div id="wrapper">
<div id="submittedHolder"></div>
<div class="formBox">
<form method="post" action="">
<p class="introText">Please Enter Some Text</p>
<textarea rows="5" cols="20" name="textForm" class="formText"></textarea>
<input type="submit" class="submitter" value="Submit">
</form>
<div class="textadder"><p>More Text</p></div>
<div class="clearer"></div>
</div><!--formBox-->
</div><!--wrapper-->
</body>
</html>
Thanks!
Use textForm[] in your textarea name instead of textForm:
<textarea rows="5" cols="20" name="textForm[]" class="formText"></textarea>
After that all "textForm" textareas would be in $_POST['textForm'] array.
<script type="text/javascript">
$(document).ready(function() {
$('.textadder').click(function(){
$("form").append("<p class='introText2'>Enter More Text</p><textarea rows='5' cols='20' name='textForm[]' class='formText2'></textarea>");
});
});/*document ready*/
</script>
<?php
if (isset($_POST['textForm']))
{
$formTxt = $_POST['textForm'];
foreach($formTxt as $txt){
echo $txt;
}
}
?>
</head>
<body>
<div id="wrapper">
<div id="submittedHolder"></div>
<div class="formBox">
<form method="post" action="">
<p class="introText">Please Enter Some Text</p>
<textarea rows="5" cols="20" name="textForm[]" class="formText"></textarea>
<input type="submit" class="submitter" value="Submit">
</form>
<div class="textadder"><p>More Text</p></div>
<div class="clearer"></div>
</div><!--formBox-->
</div><!--wrapper-->
</body>
</html>
Use array here.
the post object will now be an array.