My iconpicker button submits my HTML form - php

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>

Related

How to show pictures based on what answer filled in on the form?

I have 8 buttons, each button can be clicked, when you made your selection you go search, after you searched I need to show pictures based on what buttons are clicked before searching. I already have button that has be choosen in a array in PHP, but I dont know how to show the picture that has to be showed of depending on what buttons are used.
<form id="search" action="programmer.php" method="get">
<div data-toggle="buttons">
<div class="container">
<div class="row">
<div class="col-sm-4">
<label class="btn btn-primary btn-block btn-lg-lg">
<input type="checkbox"style="display: none;" name="lang[]" value="html" autocomplete="off">HTML
</label>
</div>
<div class="col-sm-4">
<label class="btn btn-primary btn-block btn-lg-lg">
<input type="checkbox" style="display: none;" name="lang[]" value="css" autocomplete="off">CSS
</label>
</div>
<div class="col-sm-4">
<label class="btn btn-primary btn-block btn-lg-lg">
<input type="checkbox" style="display: none;" name="lang[]" value="javascript" autocomplete="off">Javascript
</label>
</div>
</div>
</div>
<div class="container">
<input type="submit" value="Search" class="btn btn-primary btn-lg btn-block" >
</div>
This is the PHP only showing off that I got the arrays:
<?php
print_r($_GET["lang"]);
?>
Remove style="display: none;" so that checkbox are visible in the web page.Insert the name of your images in value attribute of the checkbox. When you will click on search button all the images selected in checkbox list will be displayed on the next web page.
Add following code to the programmer.php
<?php
$path_to_img_dir="path1/";
$arr=$_GET['lang'];
foreach($arr as $val){
echo sprintf("<img src='%s%s.jpg' /><br>",$path_to_img_dir,$val);
}
?>
You can save the path in a variable in php and the use it in the html code <img src='<?php echo $path;?>'>

Submit button doesn't fire

My submit button suddenly stopped working. It submits data into a MySQL database.
While I was doing some design changes, it suddenly stopped working.
Are there any apparent errors/mistakes in the code below?
I'm a noob who's currently trying to learn some PHP and so on, so any help would be much appreciated. :)
<section id="moviesearch">
<!-- Section -->
<div class="subcribe2">
<div class="container">
<!-- Container -->
<div class="row">
<!-- Row -->
<div class="col-md-4">
</div>
<body ng-app="myApp">
<div ng-controller="MyCtrl" class="col-md-4">
<form class="form-watch-list-create">
<input required="required" placeholder="Movie title" type="text" class="form-control" typeahead="item.Title for item in getLocation($viewValue)" typeahead-loading="loadingLocations" typeahead-min-length="2" typeahead-wait-ms="1000" typeahead-on-select="onSelected($item)"
typeahead-template-url="customTemplate.html" ng-model="asyncSelected">
<i ng-show="loadingLocations" class="glyphicon glyphicon-refresh"></i>
</div>
<div class="col-md-4">
<button type="submit" class="btn btn-block btn-sm btn-dark">Add to watchlist</button>
</div>
</body>
</div>
<!-- End Row -->
</div>
<!-- End Container -->
</div>
<script type="text/ng-template" id="customTemplate.html">
<a>
<span bind-html-unsafe="match.label | typeaheadHighlight:query" style="width: auto;"></span>
({{match.model.Year}})
<!-- <img ng-src="{{match.model.Poster}}" width="120"> -->
</a>
</script>
<div ng-controller="MyCtrl">
<i ng-show="loadingLocations" class="glyphicon glyphicon-refresh"></i>
</div>
</section>
Edit
Here's the code that sends data into the MYSQL database:
function addWatchList() {
if (isset($_GET['addtowatchlist'])) {
$name = $_GET['name'];
$conn = dbmysql();
$query ="INSERT INTO watch_list values(null,'{$name}','{$_SESSION['user_id']}','NOW()')";
if (mysqli_query($conn,$query)) {
$last = "SELECT * FROM watch_list WHERE created_by = '{$_SESSION['user_id']}' order by id desc limit 1";
$data = mysqli_query($conn,$last);
while ($row = mysqli_fetch_assoc($data)) {
include "_view.php";
}
}else {
echo "An error occurred. Please try again.";
}
exit;
}
}
I am looking to your code, missing attribute action="somefile.php" and method="get" if you are planning on submitting it using the form, you should put it or if you are planning on submitting your code using javascript you can use <form onsubmit="myFunction()"> That is what you are missing. I am not seeing you addtowatchlist name from your input so that php can catch it to your isset.
The submit button isn't inside the form.
You're missing the </form> tag to end the <form>. But you have </div> that matches the <div> just before </form>, so it's implicitly closing the <form> tag as well. Then you have <input type="submit"> after it. Since the submit button isn't inside the form, and has no form tag associating it with the form, it doesn't know which form it should submit when you click on it.
Try this:
<form class="form-watch-list-create">
<div ng-controller="MyCtrl" class="col-md-4">
<input
required="required"
placeholder="Movie title"
type="text"
class="form-control"
typeahead="item.Title for item in getLocation($viewValue)"
typeahead-loading="loadingLocations"
typeahead-min-length="2"
typeahead-wait-ms="1000"
typeahead-on-select="onSelected($item)"
typeahead-template-url="customTemplate.html"
ng-model="asyncSelected">
<i ng-show="loadingLocations" class="glyphicon glyphicon-refresh"></i>
</div>
<div class="col-md-4">
<button type="submit" class="btn btn-block btn-sm btn-dark">Add to watchlist</button>
</div>
</form>
This puts the form around both columns.
Use the method attribute in form tag and end the form tag properly
<form role="form" method="get" class="form-watch-list-create">
<div ng-controller="MyCtrl" class="col-md-4">
<input
required="required"
placeholder="Movie title"
type="text"
class="form-control"
typeahead="item.Title for item in getLocation($viewValue)"
typeahead-loading="loadingLocations"
typeahead-min-length="2"
typeahead-wait-ms="1000"
typeahead-on-select="onSelected($item)"
typeahead-template-url="customTemplate.html"
ng-model="asyncSelected">
<i ng-show="loadingLocations" class="glyphicon glyphicon-refresh"></i>
</div>
<div class="col-md-4">
<button type="submit" class="btn btn-block btn-sm btn-dark">Add to watchlist</button>
</div>
</form>

php can't get the text from a text area

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>

Bootstrap button input group wont display correctly with <form> tags

So I'm working on a social networking Facebook type proof of concept project for college and I'm trying to get a Bootstrap, multi-button input group to display properly for a comment box.
I would like to have the text area, with a Comment and Like button on the right hand side, with the whole input group filling the width of the panel as seen below.
Trying to achieve this!
The problem is when I add in my <form> tags, the formatting of the entire group within <div class="row"> goes crazy and forms a little box on the left hand side (screenshot below).
If I take out the <form> tags formats properly, but I'm just not sure how to manage the <form> tags/where to put them to achieve this multi-button group.
How it displays currently
The code below is a few undos later to when the forms weren't broken, just so you know this isn't how I originally went about achieving it, but what i've succumbed to for now.
If anyone knows how to achieve this I'd be so grateful!
while($row = mysqli_fetch_assoc($result)) {
//Get relative timestamp for current post
$timestamp = strtotime($row['StatusTimestamp']);
$stampRelative = CheckTimestamp($timestamp);
echo '<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">'.$row['UserName'].'<small class="postTimestamp"> '.$stampRelative.'</small></h3>
</div>
<div class="panel-body">
'.$row['StatusContent'].'
</div>
<div class="panel-footer clearfix">';
echo ' <div class="row">
<div class="col-lg-11">
<div class="input-group">
<form action="'.CommentOnStatus($row['StatusID']).'" method="post">
<input type="text" class="form-control" name="comment" placeholder="Post a comment...">
<span class="input-group-btn">
<button class="btn btn-default" type="submit">Comment</button>
<input type="hidden" name="statusId" value="'.$row['StatusID'].'">
</span>
</form>
</div>
</div>
<div class="col-lg-1">
<form action="'.LikeStatus($row['StatusID']).'" method="post">
<button type="submit" id="like" name="'.$row['StatusID'].'" class="btn btn-primary pull-right">Like</button>
</form>
</div>
</div>
</div>
</div>';
}
I checked your code. This should work fine. Let me know if this does not work. THere are minor problems of placing the elements. Please Use this in your row :
<div class="col-lg-11">
<form method="post">
<div class="input-group">
<input type="text" class="form-control" name="comment" placeholder="Post a comment...">
<span class="input-group-btn">
<button class="btn btn-default" style="border-width: 1px 0 1px 0;border-radius: 0;" type="submit">Comment</button>
<button type="submit" id="like" name="'" class="btn btn-primary" style="border-radius: 0 5px 5px 0;">Like</button>
</span>
<input type="hidden" name="statusId" value="">
</div>
</form>
</div>
This is my output
Use the classnavbar-form in your form. It should work fine now.
So form will look like <form action="'.CommentOnStatus($row['StatusID']).'" method="post" class="navbar-form">

Submitting to database from modal view

I have a file, let`s name it dashboard.php, in this file i load a modal window and trough this window i want to submit a form and the form action is also written in this dashboard.php file. is this possible? i am acutally trying it this way, but it s not working:
dashboard:php
<?php $modal_gerade_geschlossen = $_POST['abgespeichert'];
if ($modal_gerade_geschlossen == 1){
$neue_addy = $_POST['neue_addy'];
$benach_ja_nein = $_POST['benach_ja_nein'];
mysql_query("INSERT INTO mitglieder (email,benachrichtigung)VALUES('$neue_addy','$benach_ja_nein')");
}
?>
<div class="modal-body" style="height:194px">
<div>
<form name="losgehts" method="post" action="../dashboard.php">
<div style="float:left">
<input name="neue_addy" style="width:270px" type="text"/>
</div>
</div>
<div>
<select name="benach_ja_nein" >
<option>ja</option>
<option>nein</option>
</select>
</div>
<input type="hidden" name="abgespeichert" value="1"/>
<button type="button" class="btn btn-default" data-dismiss="modal">Schließen</button>
<input type="submit" name="submit" class="btn btn-primary" value="Speichern"/>
</form>
</div>
</div>

Categories