Hi gladly I want to put the output of my rows from a table in on single text field. This is what I currently have in my view:
{{Form::label('tag', 'tags')}}
#foreach ($task->tagtask as $tt)
<input type="text" name="tag_name" class="form-control" value='{{ $tt->tag['tag_name'] }}'>
#endforeach
The problem is if I have a task with for example 2 tags. Then its going to loop two times and then I have two textfields with each a value of a single tag. I would like to have one single textfield with all the tags that a task has as a value. But I really don't know how to achieve this.
Can someone help me, please? Gladly I'm waiting for your response. Anyway thanks for your answer.
You can use #foreach inside the value attribute:
{{Form::label('tag', 'tags')}}
<input type="text" name="tag_name" class="form-control" value='#foreach ($task->tagtask as $tt) {{ $tt->tag['tag_name'] }} #endforeach'>
You can always use a little of pure PHP.
{{Form::label('tag', 'tags')}}
<input type="text" name="tag_name" class="form-control" value="<?php foreach($task->tagtask as $tt) echo $tt->tag['tag_name'];?>">
Related
I have looked everywhere so I apologize if there's an answer to this already, I couldn't find it after hours of searching. Maybe it's not a good way to do it either...
I have a form that has "picks" of a litter, so 1st pick, 2nd pick, 3rd pick, etc. These picks also have genders (Female, Male)
I use a foreach query to grab the available pick spots. If someone isn't assigned to that pick spot, then the input field is enabled for manual typing
Within that foreach query, I need to somehow submit what pick it is and what gender, as well as the typed value, so I can find the pick and store it to the database... The other problem is, it's dynamic where someone may type in 3 input fields, or other times just 1 input field. Basically it'll show 3 input fields and the user can choose to use all 3 or just 1...
No matter what I've tried, it doesn't work. I don't even have my examples because I've tried everything I could find and had to scrap it all
The input, this is for males only but females are the same:
<?php
foreach ($malespickedquery as $pick){
$picktaken=$pick['user_id'];
$pickcustom=$pick['custom_name'];
$pickposition=$pick['pick_id'];
$suffix=ordinal($pickposition);
?>
<div class="form-row pb-3">
<div class="col-12">
<label class="control-label"><?php echo $pickposition.$suffix." Pick "; ?>Male:</label>
<?php if($pickcustom==true){ ?>
<input type="text" name="" class="form-control" value="<?php echo $pickcustom; ?>" />
<?php }elseif($picktaken!="0"){ ?>
<input type="text" name="" class="form-control" value="<?php echo $pick['public_name']; ?>" disabled />
<?php }else{ ?>
<input type="text" name="malepicks[<?php echo $pickposition; ?>][male][]" class="form-control" value="" />
<?php } ?>
</div>
</div>
<?php } ?>
I've tried foreach within foreach, but can never get all information. Most things just return the last input field as well... So if 3 of them are generated, the last input field would come through but not the others. I also did something with foreach where it returned ALL of the fields, even blank ones, which just got confusing and still didn't work right
Thank you in advance!
Im using laravel 6.0 and have issue with Trix wysiwyg. How to get value to trix editor. The problem is not how to pass it to the view, where I using trix, the problem is how to display it - for example here iam geting content (title) by "value":
Title: </br><input type="text" id='title' name='title' value="{{$article->title}}"></br>
but how to $article->title in Trix, to have chance to edit it? :)
#trix(\App\Article::class, 'title')
just put a value to the hidden input of trix
<input id="short_desc" type="hidden" name="product_short_description" value="{{ $product->product_short_description ?? "" }}" >
<trix-editor input="short_desc" placeholder="Product short description"></trix-editor
I know this is a weird question and maybe there are better solutions but in this step of my project it difficult to reform project.
I have some pairs of tags in my html similar to this:
<div>
<label for="first">text</label>
<input id="first" />
</div>
<div>
<label for="second">text</label>
<someTag></someTag>
<input id="second" />
</div>
I intend to generate this html with php, some thing like this code:
<?php
$form = new htmlform('formname');
echo $form->label('text');
echo $form->input('first');
echo $form->label('text');
echo $form->input('first');
?>
here is the problem...
as you see I type input id in second line but labels need that id too.
how can I put text in second line and use that in first line?
any byref or some thing.?.
Can you consider some
labeled_input(id, text)
that generates both, the label and the input?
I have a loop of checkboxes with multiple attributes. One content may have many attributes, so user can check more than one attribute.
If some validation errors occurs in this form I need to pre-fetch already checked attribute.
#foreach($attributes as $entry)
<div class="check-line">
<input type="checkbox" id="cat4" class='icheck-me'
name="attribute[<?php echo $entry->id; ?>]"
data-skin="square"
data-color="blue"
value="{{$entry->id}}"
<?php
if(Input::old('attribute['.$entry->id.']')== $entry->id) {
echo 'checked="checked"';
}
?>
/>
<label class='inline' for="cat4">
<strong>{{$entry->name}}</strong>
</label>
</div>
#endforeach
I tried above but no luck.. any ideas?
From Laravel docs on Requests:
"When working on forms with "array" inputs, you may use dot notation to access the arrays:"
$input = Input::get('products.0.name');
So you should be able to do this fpr Input::old() as well:
<?php
if(Input::old('attribute.' . $ii) == $entry->id) {
echo 'checked="checked"';
}
?>
A slightly more catch-all answer to this would be to do an array search rather than just checking the current index. As such, I see the code looking like this:
#foreach($attributes as $entry)
<div class="check-line">
<input type="checkbox" id="cat4_{{{ $entry->id }}}" class="icheck-me"
name="attribute[]"
data-skin="square"
data-color="blue"
value="{{{ $entry->id }}}"
#if (in_array($entry->id, Input::old('attribute')))
checked
#endif
/>
<label class="inline" for="cat4_{{{ $entry->id }}}">
<strong>{{{ $entry->name }}}</strong>
</label>
</div>
#endforeach
So first off I've made the code more Blade-compliant:
Any echos are now {{{ and }}} rather than the previous mix of <?php echo ___; ?> and {{/}} (I went for {{{ rather than {{ as it's not HTML being echoed and it's better to be safer)
The <?php if () { is now a Blade #if ()
The name attribute is now just a standard array (doesn't include indices, as it doesn't need to), however the id attribute previously gave all checkboxes the same ID. While browsers will let you do this, it's technically illegal HTML, so I've appended the entry ID to each checkbox.
Finally, the if condition no longer checks that the value of the input with the current index matches the current entry's ID, but instead searches to see if the current entry's ID is anywhere in the returned array. This protects against the possibility of your entries being returned in a different order to the previous time they were on the page.
We now don't have a reliance on the $ii variable, so it can be removed too.
Caveats:
In doing this I've made the code a little nicer, but the code is no longer identical. Without knowing exactly why you use the $ii variable in order to provide keys to your attribute array I can't say that using my code will work correctly. However, assuming it was just there to help with this old input thing, then it's fine.
Also, my change of {{ to {{{ may have consequence I don't know about. I'd have thought for the $entry->id stuff it'd be fine, but maybe $entry->name in the <label> need to be unescaped HTML for a reason. Feel free to change this back.
I have a set of inputs - 4 questions which are each arrays (could range from 1-100 keys) - they may or may not start at 1 (may be like 95,96,97,98...)
I need to simultaneously pull the input from all 4 questions for each key 1 at a time, unfortunately I can not quite figure out how...
I am familiar with the foreach statement and I think it will probably be my best bet:
here is what I have
<textarea name="question[98]" rows="3" cols="60"></textarea>
<select name="anstype[98]">
<option value="break">Section Title</option>
...more options
</select>
<input name="d_on[98]" type="text" size="10">
<input name="a_d_on[98]" type="text" size="10">
the next set of inputs could be
<textarea name="question[99]" rows="3" cols="60"></textarea>
<select name="anstype[99]">
<option value="break">Section Title</option>
...more options
</select>
<input name="d_on[99]" type="text" size="10">
<input name="a_d_on[99]" type="text" size="10">
ideally I need to get these into a mysql insert statements
$insquery = "INSERT INTO questions (question, anstype, d_on, a_d_on) VALUES('$_POST['question[98]']', '$_POST['anstype[98]']', '$_POST['d_on[98]']', '$_POST['a_d_on[98]']') ";
again I cant know what the key is going to start at, any help is appreciated
foreach($_POST["question"] as $key=>$value)
{
$question=$value;
$anstype=$_POST["anstype"][$key];
$d_on=$_POST["d_on"][$key];
$a_d_on=$_POST["a_d_on"][$key];
// Run your query here for one complete entry and it will repeat with loop
}
You need to use the key like this:
$_POST['question'][]
In your case, for example: 98: $_POST['question'][98], but its better to iterate over it.