Laravel not seeing form - php

This is my controller
public function store(Request $request)
{
if ($request->has('order')){
dd('nice');}
} else if ($request->has('delete')){
$fileToDelete = $request->input('delete');
Image::where('id', $fileToDelete)->delete();
return redirect('settings/photos');
This is my blade file
<form action="{{route("settings.postphotos")}}" name="order" method="post">
#csrf
<label for="sort">Order by : </label><select name="sort" form="order">
<option value="name">Name</option>
<option value="dateAdded">Date added</option>
</select><select name="sortBy" form="order">
<option value="asc">Ascending</option>
<option value="des">Descending</option>
</select><input type="submit" value="Order" class="settings-photos-delete-btn"/>
</form>
<form action="{{route("settings.postphotos")}}" method="post" name="delete" class="text-center">
#csrf
<input type="hidden" name="delete" value="{{$images->id}}" />
<input type="submit" value="Delete" class="settings-photos-delete-btn"/><br/>
</form>
The controller sees the delete form but not the order form please what am i doing wrong

You don't have a input named "order" in your order form
create/rename one
<form action="{{route("settings.postphotos")}}" name="order" method="post">
#csrf
<label for="sort">Order by : </label><select name="sort" form="order">
<option value="name">Name</option>
<option value="dateAdded">Date added</option>
</select><select name="sortBy" form="order">
<option value="asc">Ascending</option>
<option value="des">Descending</option>
</select><input type="submit" name="order" value="Order" class="settings-photos-delete-btn"/>
</form>

Related

Show DIV based on form value

I have a database driven table where the last column in the table contains a form that repeats for each row. I want to have a day_inperson field show if the value in the spring_2021_status field is equal to "Both" Since the form is repeated on the page, it doesn't work.
Here is my code for the repeating form. The form itself works fine and inserts into the database. Just need the one field to show if it meets the value of "Both":
<form id="update_location" name="update_location" method="POST">
<div class="form-group">
<br>
<strong>Select a New Location:</strong>
<select class="form-control" id="spring_2021_status" name="spring_2021_status">
<option></option>
<option value="In Person" <?php if (!(strcmp('In Person', ($survey->getColumnVal("spring_2021_status"))))) { echo "selected=\"selected\"";} ?>>In Person</option>
<option value="Remote" <?php if (!(strcmp('Remote', ($survey->getColumnVal("spring_2021_status"))))) {echo "selected=\"selected\"";} ?>>Remote</option>
<option value="Both" <?php if (!(strcmp('Both', ($survey->getColumnVal("spring_2021_status"))))) {echo "selected=\"selected\"";} ?>>Both</option>
<option value="N/A" <?php if (!(strcmp('N/A', ($survey->getColumnVal("spring_2021_status"))))) {echo "selected=\"selected\"";} ?>>N/A</option>
</select>
<br>
<script>
$('#spring_2021_status').on('change',function(){
if( $(this).val()==="Both"){
$("#update_status2").show()
}
else{
$("#update_status2").hide()
}
});
</script>
<div class="row" id="update_status2" style="display:none;">
<div class="col mb-2"><label for="days_inperson"><strong>Which days?</strong> (Hold down CTRL to select multiple ones)</label>
<select multiple class="form-control" id="days_inperson" name="days_inperson">
<option value="Mon">Mon</option>
<option value="Tues">Tues</option>
<option value="Wed">Wed</option>
<option value="Thurs">Thurs</option>
<option value="Fri">Fri</option>
</select>
</div>
</div>
<strong>Add Note:</strong>
<textarea id="notes" name="notes" rows="4" cols="50">
<?php echo($survey->getColumnVal("notes")); ?></textarea>
</div>
<input type="hidden" value="<?php echo($survey->getColumnVal("theein")); ?>" name="ein" id="ein">
<button type="submit" name="submit3" id="submit3" class="btn btn-info">Update Location Status</button>
</form>
You can use class selector inside your div update_status2 then whenever your select-box gets change use $(this).closest('form').find().. this line will get closest form from select-box and then find your div which you need to show/hide.
Demo Code :
//onchange of sleect
$('[name=spring_2021_status]').on('change', function() {
if ($(this).val() === "Both") {
//get closest form tag and then find your div
$(this).closest('form').find(".update_status2").show()
} else {
$(this).closest('form').find(".update_status2").hide()
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<form id="update_location" name="update_location" method="POST">
<div class="form-group">
<br>
<strong>Select a New Location:</strong>
<select class="form-control" name="spring_2021_status">
<option></option>
<option value="In Person" selected>In Person</option>
<option value="Remote">Remote</option>
<option value="Both">Both</option>
<option value="N/A">N/A</option>
</select>
<br>
<!--added class-->
<div class="row update_status2" style="display:none;">
<div class="col mb-2"><label for="days_inperson"><strong>Which days?</strong> (Hold down CTRL to select multiple ones)</label>
<select multiple class="form-control" id="days_inperson" name="days_inperson">
<option value="Mon">Mon</option>
<option value="Tues">Tues</option>
<option value="Wed">Wed</option>
<option value="Thurs">Thurs</option>
<option value="Fri">Fri</option>
</select>
</div>
</div>
<strong>Add Note:</strong>
<textarea id="notes" name="notes" rows="4" cols="50">
something...</textarea>
</div>
<input type="hidden" value="abc" name="ein" id="ein">
<button type="submit" name="submit3" id="submit3" class="btn btn-info">Update Location Status</button>
</form>
<form id="update_location" name="update_location" method="POST">
<div class="form-group">
<br>
<strong>Select a New Location:</strong>
<select class="form-control" name="spring_2021_status">
<option></option>
<option value="In Person" selected>In Person</option>
<option value="Remote">Remote</option>
<option value="Both">Both</option>
<option value="N/A">N/A</option>
</select>
<br>
<div class="row update_status2" style="display:none;">
<div class="col mb-2"><label for="days_inperson"><strong>Which days?</strong> (Hold down CTRL to select multiple ones)</label>
<select multiple class="form-control" id="days_inperson" name="days_inperson">
<option value="Mon">Mon</option>
<option value="Tues">Tues</option>
<option value="Wed">Wed</option>
<option value="Thurs">Thurs</option>
<option value="Fri">Fri</option>
</select>
</div>
</div>
<strong>Add Note:</strong>
<textarea id="notes" name="notes" rows="4" cols="50">
something...</textarea>
</div>
<input type="hidden" value="abc" name="ein" id="ein">
<button type="submit" name="submit3" id="submit3" class="btn btn-info">Update Location Status</button>
</form>

Selected option doesnt work in form

I'm using Contao as CMS and for a filter, I need to build my own select.
This is my Code, what is working so fare:
<form action="media-center" id="cc_filter_339" name="cc_filter_339" method="get" enctype="application/x-www-form-urlencoded" onchange="this.submit();">
<div class="formbody">
<select class="" name="language">
<option value="language_reset">Sprache</option>
<option value="de">Deutsch</option>
<option value="en">English</option>
<option value="fr">Français</option>
<option value="nl">Nederlands</option>
</select>
<div class="widget submit_container clearall clear_all_filters">
<input type="submit" id="ctrl_cc_filter_339_clearall" class="submit clearall clear_all_filters" value="Filter zurücksetzten" name="cc_filter_339_clearall">
</div>
</div>
</form>
The only problem is, the option "Sprache" is always selcted, it dosnt mater which option I click.
I hope you guys can help my with that.
You need to check $_GET value and then add selected attribute to your options. Do like below:-
<form action="media-center" id="cc_filter_339" name="cc_filter_339" method="get" enctype="application/x-www-form-urlencoded" onchange="this.submit();">
<div class="formbody">
<select class="" name="language">
<option value="language_reset" <?php if(isset($_GET['language']) && $_GET['language']=='anguage_reset'){echo "selected";}?>>Sprache</option>
<option value="de" <?php if(isset($_GET['language']) && $_GET['language']=='de'){echo "selected";}?>>Deutsch</option>
<option value="en" <?php if(isset($_GET['language']) && $_GET['language']=='en'){echo "selected";}?>>English</option>
<option value="fr" <?php if(isset($_GET['language']) && $_GET['language']=='fr'){echo "selected";}?>>Français</option>
<option value="nl" <?php if(isset($_GET['language']) && $_GET['language']=='nl'){echo "selected";}?>>Nederlands</option>
</select>
<div class="widget submit_container clearall clear_all_filters">
<input type="submit" id="ctrl_cc_filter_339_clearall" class="submit clearall clear_all_filters" value="Filter zurücksetzten" name="cc_filter_339_clearall">
</div>
</div>
</form>

(Help) Get results from multiple dropdown with one submit button

I make four horizontal dropdown menu. Here is my code :
<div class="MenuSearching" id="Searching">
<div class="Menu1" id="Menu1">
<p> Lembaga</p>
<form style="margin-top:-20px;margin-left:-2px;">
<select name="DropLembaga" autofocus required id="DropLembaga">
<option value="no" selected="selected">---Choose one---</option>
<option value="FlashCom">FlashCom</option>
<option value="InterNusa">InterNusa</option>
<option value="HexaCompare">HexaCompare</option>
</select>
</form>
</div>
<div class="Menu2" id="Menu2">
<p> Paket Kursus</p>
<form style="margin-top:-20px;margin-left:-2px;">
<select name="DropBahasa" autofocus required id="DropBahasa">
<option value="no" selected="selected">---Choose one---</option>
<option value="web">Kursus Web Design</option>
<option value="flash">Kursus Flash Animation</option>
<option value="marketing">Kursus Internet Marketing</option>
</select>
</form>
</div>
<div class="Menu3" id="Menu3">
<p> Lokasi</p>
<form style="margin-top:-20px;margin-left:-3px;">
<select name="DropLokasi" autofocus required id="DropLokasi">
<option value="no" selected="selected">---Choose one---</option>
<option value="timur">Surabaya Timur</option>
<option value="barat">Surabaya Barat</option>
<option value="utara">Surabaya Utara</option>
<option value="selatan">Surabaya Selatan</option>
</select>
</form>
</div>
<div class="Menu4" id="Menu4">
<p> Harga</p>
<form style="margin-top:-20px;margin-left:-2px;">
<select name="DropHarga" autofocus required id="DropHarga">
<option value="no" selected="selected">---Choose one---</option>
<option value="harga1"> kurang dari Rp.750.000</option>
<option value="harga2">Rp.750.000 - Rp.1.500.000</option>
<option value="harga3">Rp.1.500.000 - Rp.2.500.000</option>
<option value="harga4">lebih dari Rp.2.500.000</option>
</select>
</form>
</div>
<div>
<input name="submitbutton" type="submit" id="submitbutton" formmethod="POST" value="search">
</div>
</div>
My question, how to make the submit button from these multiple dropdown (and get the results)?
Is my code above efficient?
Thank you for the answer!
First thing would be to change your form tags to divs to keep your formatting.
<div class="Menu1" id="Menu1">
<p> Lembaga</p>
<div style="margin-top:-20px;margin-left:-2px;">
<select name="DropLembaga" autofocus required id="DropLembaga">
<option value="no" selected="selected">---Choose one---</option>
<option value="FlashCom">FlashCom</option>
<option value="InterNusa">InterNusa</option>
<option value="HexaCompare">HexaCompare</option>
</select>
</div>
</div>
Next you will need to surround your entire form with <form></form> tags. I would place the open form tag just below the opening of your first div.
<div class="MenuSearching" id="Searching">
<form action="" method="post">
<div class="Menu1" id="Menu1">
.
.
.
</div>
<div class="Menu2" id="Menu2">
.
.
.
</div>
<div class="Menu3" id="Menu3">
.
.
.
</div>
<div class="Menu4" id="Menu4">
.
.
.
</div>
<div>
<input name="submitbutton" type="submit" id="submitbutton" formmethod="POST" value="search">
</div>
</form>
</div>

Pass code using POST method

I made a form that receives source code that can be written in C/C++/Python/Java/Ruby
<?php
if(isset($_GET['id']))
{
$problem_code=$_GET['id'];
echo '<form name="submit-button" action="/codejudge/result-board.php?id='.$problem_code.'" method="post">';
}
?>
<textarea id="editor" class="editor" rows="25" cols="100" name="code">
</textarea>
<select id="lang" name="lang" class="lang">
<option value="11" selected>C</option>
<option value="41">C++</option>
<option value="4">Python 2</option>
<option value="116">Python 3</option>
<option value="55">Java</option>
<option value="17">Ruby</option>
</select>
<button type="submit" >Submit</button>
</form>
and here is the code for result-board.php
<?php
include "conn_db.php";
$code=stripcslashes($_POST['code']);
$lang= stripcslashes($_POST['lang']);
echo $code.$lang;
?>
What should I use in case of POST method so that correct data can be receive.
I think you can also try:
<?php
if(isset($_GET['id']))
{
$problem_code=$_GET['id'];
}else{
$problem_code=0;
}
echo '<form name="submit-button" action="/codejudge/result-board.php" method="post">';
echo '<input type="hidden" value="'.$problem_code.'" name="id"/>';
?>
<textarea id="editor" class="editor" rows="25" cols="100" name="code"></textarea>
<select id="lang" name="lang" class="lang">
<option value="11" selected>C</option>
<option value="41">C++</option>
<option value="4">Python 2</option>
<option value="116">Python 3</option>
<option value="55">Java</option>
<option value="17">Ruby</option>
</select>
<button type="submit" >Submit</button>
</form>
your form should be something like:
<form name="submit-button" action="/codejudge/result-board.php' method="post">
and then add your problem code like,
<input type="hidden" value="<?php echo $problem_code;?>" name="code"/>
and then access with your name like,
$_POST['code']

Create a PHP function to display an HTML form?

Instead of repeating myself with my form:
<form name="addBlockList" action="" method="post">
Välj blockeringsgrad:
<select name="blockeringsgrad" style="font-size: 12px;">
<option value="1">1 - Bilder</option>
<option value="2">2 - Bilder, Vän, Vägginlägg, PM</option>
<option value="3">3 - Ingen tillgång till profil</option>
</select>
<input type="hidden" name="uID" value="$id">
<br>
<input type="submit" value="Lägg till">
</form>
I would like to just call a function and then it would show this form. Could you do that? And for the uID, could i have a parameter to the function?
<?php
function showForm($uid){
?>
<form name="addBlockList" action="" method="post">
Välj blockeringsgrad:
<select name="blockeringsgrad" style="font-size: 12px;">
<option value="1">1 - Bilder</option>
<option value="2">2 - Bilder, Vän, Vägginlägg, PM</option>
<option value="3">3 - Ingen tillgång till profil</option>
</select>
<input type="hidden" name="uID" value="<?=$uid?>">
<br>
<input type="submit" value="Lägg till">
</form>
<?php
}
EDIT:
If you want this method to return the form you could use output buffering like so:
<?php
function showForm($uid){
ob_start();
?>
<form name="addBlockList" action="" method="post">
Välj blockeringsgrad:
<select name="blockeringsgrad" style="font-size: 12px;">
<option value="1">1 - Bilder</option>
<option value="2">2 - Bilder, Vän, Vägginlägg, PM</option>
<option value="3">3 - Ingen tillgång till profil</option>
</select>
<input type="hidden" name="uID" value="<?=$uid?>">
<br>
<input type="submit" value="Lägg till">
</form>
<?php
return ob_get_clean();
}
There is an extensive article on this but basically here is the code. https://a1websitepro.com/create-form-php-function/
<?php
function form(){
echo '
<form method="post" action="">
<input type="text"name="firstName"/>
<input type="submit" name="submit" value="submit"/>
</form>
';
}
?>
Or you can use the HEREDOC syntax to put your form into a string within a php function:
<?php
function display_form($uid) {
$str = <<<EOT
<form name="addBlockList" action="" method="post">
Välj blockeringsgrad:
<select name="blockeringsgrad" style="font-size: 12px;">
<option value="1">1 - Bilder</option>
<option value="2">2 - Bilder, Vän, Vägginlägg, PM</option>
<option value="3">3 - Ingen tillgång till profil</option>
</select>
<input type="hidden" name="uID" value="$uid">
<br>
<input type="submit" value="Lägg till">
</form>
EOT;
return $str;
}
echo display_form(1);
?>

Categories