Here is the deal (using php and laravel-5.2).
I have some forms in a page, and when i submit another form not the first one then it keeps submit the first form.
Here my html code:
<form method="POST" action="http://localhost:8888/candidates/18" accept-charset="UTF-8" id="name-edit" style="display:none">
<input name="_method" type="hidden" value="PUT">
<input name="_token" type="hidden" value="xxzvu6HIqP8k2kg78pxuHiTc8NWftjNL1IJvxbDo">
<div class="form-group ">
<div class="col-xs-12 col-sm-5 ">
<input placeholder="Full Name" error="" id="name-input" class="width-100" name="name" type="text" value="chi qua uqaaa1232">
</div>
</div>
<button class="green btn-link col-xs-4" type="submit"><i class="ace-icon glyphicon glyphicon-ok"></i> Click to save or press Enter</button>
</form>
<form method="POST" action="http://localhost:8888/candidates/18" accept-charset="UTF-8" id="address-edit" style="display:none">
<input name="_method" type="hidden" value="PUT">
<input name="_token" type="hidden" value="xxzvu6HIqP8k2kg78pxuHiTc8NWftjNL1IJvxbDo">
<div class="form-group ">
<div class="col-xs-12 col-sm-5 ">
<input placeholder="Address" error="" id="address-input" class="width-100" name="address" type="text" value="nha xacdawdwad">
</div>
</div>
<button class="green btn-link col-xs-4" type="submit"><i class="ace-icon glyphicon glyphicon-ok"></i> Click to save or press Enter</button>
</form>
My jquery code for both forms:
$(document).ready(function(){
$("#name-edit").focusout(function() {
$('#name-edit').css('display', 'none');
$('#name-view').css('display', 'inline');
});
$("#address-edit").focusout(function() {
$('#address-edit').css('display', 'none');
$('#address-view').css('display', 'inline');
});
});
$('#btn-edit-name').click(function () {
var name = $('#name-view').css('display', 'none').clone().children().remove().end().text();
$('#name-input').val(name);
$('#name-edit').css('display', 'inline').focus();
});
$('#btn-edit-address').click(function () {
var name = $('#address-view').css('display', 'none').clone().children().remove().end().text();
$('#address-input').val(name);
$('#address-edit').css('display', 'inline').focus();
});
btn-edit-name and btn-edit-address for showing the form. thanks for your consider.
here is my UI:
You can't submit 2 forms simultaneously.
Instead of having 2 forms for name and address fields you can add them into single form like below:
<form method="POST" action="http://localhost:8888/candidates/18" accept-charset="UTF-8" id="name-edit" style="display:none">
<input name="_method" type="hidden" value="PUT">
<input name="_token" type="hidden" value="xxzvu6HIqP8k2kg78pxuHiTc8NWftjNL1IJvxbDo">
<div class="form-group ">
<div class="col-xs-12 col-sm-5 ">
<input placeholder="Full Name" error="" id="name-input" class="width-100" name="name" type="text" value="chi qua uqaaa1232">
</div>
</div>
<div class="form-group ">
<div class="col-xs-12 col-sm-5 ">
<input placeholder="Address" error="" id="address-input" class="width-100" name="address" type="text" value="nha xacdawdwad">
</div>
</div>
<button class="green btn-link col-xs-4" type="submit"><i class="ace-icon glyphicon glyphicon-ok"></i> Click to save or press Enter</button>
</form>
If you wish to show hide them on click then you can add some jQuery to do so.
oh i found the answer that set the type submit button to button then make jquery for click event $(this).closest('form').submit()
You can either have two different actions
action="http://localhost:8888/candidates/18"
action="http://localhost:8888/candidates/19"
If not possible add different hidden input to each form like
In form 1 add this line
<input type="hidden" name="identifier" value="form1">
In form 2 add this line
<input type="hidden" name="identifier" value="form2">
Now you can either use if ($_POST['identifier'] == 'form1')
OR
You can use a switch statement also
switch($_POST['identifier']){
case 'form1':{}
case 'form2':{}
}
Also your two submit buttons are identical. You can set a value for each that you can check after submission. Set value like this
For form 1 name
<button class="green btn-link col-xs-4" type="submit" value="name" name="name"><i class="ace-icon glyphicon glyphicon-ok"></i> Click to save or press Enter</button>
For form 2 address
<button class="green btn-link col-xs-4" type="submit" value="address" name="address"><i class="ace-icon glyphicon glyphicon-ok"></i> Click to save or press Enter</button>
Related
i have a searchbox in my website like below:
<div style="" class="col-sm-8">
<div class="wrapda">
<div class="searchda">
<a href="https://google.com">
<input type="text" class="searchTermda" placeholder="Search Image">
<button type="submit" class="searchButtonda">
<i class="fa fa-search">Search</i>
</button>
</a>
</div>
</div>
</div>
am trying to pass the user entered keyword in the input box to next page , is there anyway to do this using anchor tags, please help. thanks in advance
Instead of using anchor tag, the more standard way is to use form.
<div style="" class="col-sm-8">
<div class="wrapda">
<div class="searchda">
<form method="POST" action="your target url">
<input type="text" name="searchInput" class="searchTermda" placeholder="Search Image">
<button type="submit" class="searchButtonda">
<i class="fa fa-search">Search</i>
</button>
</form>
</div>
</div>
</div>
You have to specify the action attribute in the form tag which will be your target url.
You also have to specify the name attribute in the input tag.
This way your input will be sent to your target url.
You can use form for this purpose.
<form action="https://www.google.com/search" method="GET" />
<input type="text" placeholder="Search Image" name="q" />
<input type="submit" value="Search Image" />
</form>
I have switch in my HTML form like below
<div class="form-group">
<span><b>GAME MODE?</b></span> <div class="btn-group" id="status" data-toggle="buttons">
<label class="btn btn-default btn-on">
<input type="radio" value="1" name="gamemode">ON</label>
<label class="btn btn-default btn-off active">
<input type="radio" value="0" name="gamemode" checked="checked">OFF</label>
</div>
</div>
On Submit form, I am getting all $_POST value but just not getting value of toggle switch. I think I am missing something in it. I am trying to get it like below in PHP
$gamemode=$_POST['gamemode'];
But its always empty. Can I know if anyone can help me for use properly toggle switch?
Thanks!
Your code should have a form tag with method attribute set to post. Then once the submit button is pressed the form $_POST the data and you can retrieve that info using $_POST['gamemode']. I used the below code and tested and get a 1 when ON is submitted and a 0 when OFF is submitted.
<div class="form-group">
<span><b>GAME MODE?</b></span> <div class="btn-group" id="status" data-toggle="buttons">
<form method="post">
<label class="btn btn-default btn-on">
<input type="radio" value="1" name="gamemode">ON</label>
<label class="btn btn-default btn-off active">
<input type="radio" value="0" name="gamemode" checked="checked">OFF</label>
<input type="submit" value="submit" name="submit">
</form>
</div>
i have a foreach row that displays the "message icon" (i dont think it has anything to do with the form since the form is outside the loop:
enter image description here
which displays a chat form that you can either type a chat or send an attachment:
enter image description here
How can i make one of them required before submission? I tried through multiple JQuery ways but because they are in a for loop and each of them do not have a special id, its not working. any help please? I just need it to show an alert
Here is my code for the form:
<form method="post"action="<?php echo base_url();?>form_support_chat" enctype="multipart/form-data" class="ticket-reply-form">
<div class="row">
<div class="col-xs-12">
<div class="chat-left">
<input type="text" name="message" placeholder="Type Message ..." class="form-control" autocomplete="off">
<input type="hidden" name="cst_id" value="<?php echo $cst_id; ?>">
<input type="hidden" name="arch_ticket" value="<?php echo $arch_ticket; ?>">
<input type="hidden" name="ticket_number" value="<?php echo $ticket_number?>">
</div>
<div class="chat-right">
<label>
<img src="<?php echo base_url();?>/assest/icon-img/paperclip.png" class="ic_img" >
<input type="file" name="file" class="form-control" style="display:none;" id="hidden_upload_file_chatting">
</label>
<button type="submit" class="btn btn-flat" name="reply" value="reply" >Reply</button>
<button type="button" class="btn btn-flat" data-dismiss="modal" style="margin-left: 10px !important;">Close</button>
<span id="_showName"></span>
</div>
</div>
</div>
</form>
Simply use html5's required value
<input name="cst_id" value="<?php echo $cst_id; ?>" required>
or
<input name="cst_id" value="<?php echo $cst_id; ?>" required="true">
update
Using jQuery, add id value to each input
$(document).ready(function() {
if( $('#input1').valid() || $('#input2').valid(); ):
console.log("Success");
endif;
});
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;?>'>
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