I can't figure out why this doesnt get the value of the textarea. I've been to loads of stackoverflow posts and I can't figure out what's wrong. I've tried getting values from textfields, from dropdown lists etc and they all work I just can't get the textarea to work. I've using _GET instead, still didnt work.
This is the message I get if I don't use the isset function: Notice: Undefined index: descri.
Here's the HTML:
<form role="form" action="saveform.php" method="post" name="eventform">
<div class="form-group">
<label for="descri">Description</label>
<textarea name="descri" form="eventform" style="resize:none"></textarea>
</div>
<button type="submit" class="btn btn-default" id="addform">add</button>
</form>
PHP:
<?php
if(isset($_POST['descri']))
{
echo htmlspecialchars($_POST['descri']);
} else {
echo "DOESNTWORK";
}
?>
Just remove form attribute from textarea:
<textarea name="descri" form="eventform" style="resize:none"></textarea>
Remove form attribute from textarea that is located inside the form:
<form role="form" action="saveform.php" method="post" name="eventform">
<div class="form-group">
<label for="descri">Description</label>
<textarea name="descri" style="resize:none"></textarea>
</div>
<button type="submit" class="btn btn-default" id="addform">add</button>
</form>
You have to use it only when your textarea is outside the form (remember form should have id not just name:
<form role="form" action="saveform.php" method="post" id="eventform">
<div class="form-group">
<label for="descri">Description</label>
</div>
<button type="submit" class="btn btn-default" id="addform">add</button>
</form>
<textarea name="descri" form="eventform" style="resize:none"></textarea>
Remove form="eventform" attribute from your <textarea> element. You do not need to set it as your <form> will post your data.
<form role="form" action="saveform.php" method="post" name="eventform">
<div class="form-group">
<label for="descri">Description</label>
<textarea name="descri" style="resize:none"></textarea>
</div>
<button type="submit" class="btn btn-default" id="addform">add</button>
</form>
Related
I have a problem with my iconpicker: In my form, i want the user to choose an icon. So i added an iconpicker button from FontAwsome. If i put it out of the form, it works. But when i put it into the form, what i just need to do, when i click on it, it submits the form.
I've tried to write "type='button'" but it not works.
Can someone help me and show what's wrong?
Thank you!
<body>
<form method="post" id="form1" action="page_generator.php" enctype="multipart/form-data">
<div id="free_links">
<p >other</p>
<div class="form row" id="free_a_cloner"style="display:none" >
<div class="form-group col-1">
<button name="flnk_0[]" id="ipk" class="btn btn-outline-secondary" data-icon="fas fa-mouse-pointer" role="iconpicker" ></button>
</div>
</div>
</form>
<div class="form row">
<div class="col-sm-10">
<button type="submit" form="form1" class="btn btn-primary">Submit</button>
</div>
</div>
<script>
$("#ipk").iconpicker();
</script>
</body>
Specify that the buttun isn't of type submit by adding type='button':
<button type='button' name="flnk_0[]" id="ipk" class="btn btn-outline-secondary" data-icon="fas fa-mouse-pointer" role="iconpicker" ></button>
you forget to close a div and also try with type="button". sometime it may cause issues. Try the code below and better to create a pen for better understanding or provide head code as well thanks.
<body>
<form method="post" id="form1" action="page_generator.php" enctype="multipart/form-data">
<div id="free_links">
<p >other</p>
<div class="form row" id="free_a_cloner"style="display:none" >
<div class="form-group col-1">
<button type="button" name="flnk_0[]" id="ipk" class="btn btn-outline-secondary" data-icon="fas fa-mouse-pointer" role="iconpicker" ></button>
</div>
</div>
</div>
</form>
<div class="form row">
<div class="col-sm-10">
<button type="submit" form="form1" class="btn btn-primary">Submit</button>
</div>
</div>
<script>
$("#ipk").iconpicker();
</script>
</body>
Add type="button" and check source code on browser because it could be changed by javascript after page rendered and check if there is $("button").onClick.submit like javascript code.
be sure there is only 1 type property i mean not like that:
<button type="button" type="submit">
you can use this code!!
<button type="button" form="form1" class="btn btn-primary">Submit</button>
What I want know that is that when form data is POST to a php service directly from onClick="insert.php" then is it safe. Please explain your answer with details.
for example:
<form role="form" method="POST" enctype="multipart/form-data">
<div class="form-group">
<label>User Id</label>
<input class="form-control" name="First Name">
</div>
<div class="form-group">
<label>City Id</label>
<input class="form-control" name="Last Name">
</div>
<button type="submit" class="btn btn-primary" onclick="allowStory.php">Allow</button><button type="submit" class="btn btn-primary" onclick="insert.php">Insert</button>
</form>
It also return to same page by executing php service as I wanted. But question is that is it safe? and is this type have any drawback? if yes then what are those?
Putting a filename in onclick doesn't do anything, the onclick attribute has to contain Javascript code.
If you want a submit button to go to a specific script instead of the action of the form, use the formaction attribute.
<button type="submit" class="btn btn-primary" formaction="allowStory.php">Allow</button><button type="submit" class="btn btn-primary" formaction="insert.php">Insert</button>
It's perfectly safe to do this, it's no different from specifying the action of the form in the action="scriptname.php" attribute of the <form> tag.
Use following HTML
<form role="form" method="POST" id="formsend" enctype="multipart/form-data">
<div class="form-group">
<label>User Id</label>
<input class="form-control" name="First Name">
</div>
<div class="form-group">
<label>City Id</label>
<input class="form-control" name="Last Name">
</div>
<input type="submit" name="submit" value="Submit" /></form>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script>
$(document).on('submit', '#formsend', function()
{
$.post('savedate.php', $(this).serialize(), function(data)
{
$("#sent").html(data);
});
return false;
});
and create a savedata.php or any other name and put your php code to save data in it. you can not give filename to onclick event
I am making HTML/CSS search form using PHP and MySQL. IT doesn't display data I want. Not sure what I am doing wrong. I already have PHP working output for other options, it is just this search method is not finding any results. Been stuck for a while and decided to ask.
if (isset($_POST["searchcrews"]))
{
$searchparam = "%{$_POST['search']}%";
$stmt=$conn->prepare("SELECT * FROM crewdata WHERE name LIKE ? AND is_approved =? ORDER BY (vote_up - vote_down) DESC LIMIT ?,?");
$stmt->bind_param('s',$searchparam);
$stmt->execute();
$result=$stmt->get_result();
}
HTML/CSS
<form id="searchcrews">
<div class="box">
<div class="container-4">
<input type="text" id="search" placeholder="Search crew.." />
<button type="submit" class="icon"><i class="fa fa-search"></i></button>
</div>
</div>
</form>
try this hope it helps made some modification in form and button
<form id="searchcrews" method="post">
<div class="box">
<div class="container-4">
<input type="text" id="search" name="search" placeholder="Search crew.." />
<input type="submit" class="icon" name="searchcrews">
</div>
</div>
</form>
Add the 'name' attribute to your input tag and the method to the form tag.
<form id="searchcrews" method="POST">
<div class="box">
<div class="container-4">
<input type="text" id="search" placeholder="Search crew.." />
<button type="submit" class="icon"><i class="fa fa-search"></i></button>
</div>
</div>
</form>
I have next html form:
<form class="form-horizontal" action="frames1.php" method="post">
<div class="form-group">
<label for="uri1" class="control-label">URL:</label>
<div class="controls">
<input type="text" id="uri1" placeholder="www.ejemplo.com">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancelar</button>
<input type="submit" class="btn btn-primary" id="submit" value="Visualizar" />
</div>
</form>
I want to pass the value from textbox "uri1" to a php variable.
Thats my frames1.php:
<?php
$uriValue = $_GET["uri1"];
?>
<script>
var uri = '<?php echo $uriValue;?>';
alert(uri);
</script>
But the system shows me "", not the value I put on the textbox in the form just before.
How can pass the value from the textbox to read on the php file?
Thanks!
You are using method as post in form co change this to
<?php
$uriValue = $_POST["uri1"];
?>
<script>
var uri = '<?php echo $uriValue;?>';
alert(uri);
</script>
and also add name attribute to your field. name="uri1"
that is,
<form class="form-horizontal" action="frames1.php" method="post">
<div class="form-group">
<label for="uri1" class="control-label">URL:</label>
<div class="controls">
<input type="text" id="uri1" name="uri1" placeholder="www.ejemplo.com">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancelar</button>
<input type="submit" class="btn btn-primary" id="submit" value="Visualizar" />
</div>
</form>
Here is the working link.
You send a form by POST but in your frames1.php file, you try to get the content with $_GET. So what you have to do is just change GETto POST, so it looks like
<?php
$uriValue = $_POST["uri1"];
?>
Also a bigger problem is, that your input doesn't have a name, the parameter can only be referenced by the name, not by the ID. So your input should look like that:
<input type="text" id="uri1" name="uri1" placeholder="www.ejemplo.com">
There are one mistake in HTML as well as PHP code, You have to give name to the input field's. When form is submitted to the server then It will recognize fetch values using HTML Input Field names, and If your posted form in HTML, then you have to use same method to get the values.
Try to replace bellow code with your code:
<form class="form-horizontal" action="frames1.php" method="post">
<div class="form-group">
<label for="uri1" class="control-label">URL:</label>
<div class="controls">
<input type="text" name="uri1" id="uri1" placeholder="www.ejemplo.com">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancelar</button>
<input type="submit" class="btn btn-primary" id="submit" value="Visualizar" />
</div>
</form>
Coming to your frames1.php:
<?php
$uriValue = $_POST["uri1"];
?>
<script>
var uri = '<?php echo $uriValue;?>';
alert(uri);
</script>
Let me know still not resolved.
Diff in HTML file is:
<input type="text" name="uri1" id="uri1" placeholder="www.ejemplo.com">
you didn't mention the name, then server will not recognize the element.
In PHP:
Your using POST method but your getting the values using _GET[], both are incompatible methods. So you will not get the values which are submitted by the form
<?php
$uriValue = $_POST["uri1"];
?>
You have set form method="post".
Therefore, after your form gets submitted, the value should be:
$uriValue = $_POST["uri1"];
Not
$uriValue = $_GET["uri1"];
Solutions:
1) Either change your form method method="post" to get your existing code working.
2) Change $uriValue = $_GET["uri1"]; to $uriValue = $_POST["uri1"];
My test PHP submission code:
<?php
if($_POST['create']) { echo $_POST['name']; }
?>
My HTML form code:
<form class="form-horizontal" id="ConsultantSignUp" method="post" action="#">
<div class="control-group">
<label class="control-label" for="inputForename">Name</label>
<div class="controls">
<input type="text" class="input-xlarge" id="name" name="name" rel="popover" data-content="Enter your first and last name." data-original-title="Full Name">
</div>
</div>
<div class="control-group">
<label class="control-label" for="input01"></label>
<div class="controls">
<button type="submit" class="btn btn-success" rel="create" title="create" id="create" name="create">Create My Account</button>
</div>
</div>
</form>
My error is that it doesn't even print out the name after submission. I've checked the PHP Error log and it says:
PHP Notice: Undefined index: create in /Users/**/sites/signup.php on line 2
Line 2 being 'if($_POST['create']) { echo $_POST['name']; }'.
I'm aware of the isset() method to remove the Undefined Index notice, how ever, I just want to test my form!
This is my total code...This working perfectly for me in Chrome, Explorer and Firefox. Just check it
<?php
if(isset($_POST['create']))
{
echo $_POST['name'];
}
else
{
?>
<form class="form-horizontal" id="ConsultantSignUp" method="post" action="#">
<div class="control-group">
<label class="control-label" for="inputForename">Name</label>
<div class="controls">
<input type="text" class="input-xlarge" id="name" name="name" rel="popover" data-content="Enter your first and last name." data-original-title="Full Name">
</div>
</div>
<div class="control-group">
<label class="control-label" for="input01"></label>
<div class="controls">
<button type="submit" class="btn btn-success" rel="create" title="create" id="create" name="create">Create My Account</button>
</div>
</div>
<?php
}
?>
Your <button ... name="create"> doesn't have a value so it will submit an empty string and $_POST['create'] will evaluate as false.
Give it a value.
the 'undefined index' NOTICE will go away when you use isset() function.
this often occurs when an unchecked checkbox is also posted.
the error is only there because no 'value' is passed on the submit button and the the submit button is POSTED empty.
replace submit button with,
<button value='submitbtn' type="submit" class="btn btn-success" rel="create" title="create" id="create" name="create">Create My Account</button>
PS ONLY (value='submitbtn') is added to your original button