Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8879303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:55:16+00:00 2026-06-14T19:55:16+00:00

I’ve got this input form: (Using the blade template engine with Laravel, but the

  • 0

I’ve got this input form: (Using the blade template engine with Laravel, but the html should be easy to understand from this and ultimately trivial)

{{ Form::text('amount[]', Input::old('amount')) }}
<?php echo Form::select('unit[]',
    array(
    'whole' => _('whole'),
    'ml'    => _('milliliter'),
    'l'     => _('liter'),
    'dl'    => _('deciliter'),
    'mg'    => _('milligram'),
    'g'     => _('gram'),
    'kg'    => _('kilogram'),
    'tsp'   => _('teaspoon'),
    'tbs'   => _('tablespoon'),
    )) ?>
{{ Form::text('ingredient[]', Input::old('ingredient')) }}

I’m trying to format this to my database to return it in a string like this :

<li><span>1</span> liter red wine</li>

I’m considering making it a simpler form and eliminating the unit measurement forcing my users to type it in instead for flexibility, but I’ll still have to cramp it all into one table for my database. The span tag is used in a jQuery to dynamically increase the number so is needed. I’ve been at this for quite a few days on and off but I can’t crack how to do this.

Here is my formatting logic:

$amount = Input::get('amount[]');
$unit = Input::get('unit[]');
$ingredient = Input::get('ingredient[]');

for ( $i = 0, $c = count(Input::get('ingredient[]')); $i < $c; $i++ ) 
{
    $ingredients .= '<li><span>'.$amount[$i].'</span>'.$unit[$i].' '.$ingredient[$i].'</li>';
}

and I send it using

$new = Recipe::create(array(
    'title' => Input::get('title'),
    'curiousity' => Input::get('curiousity'),
    'ingredients' => $ingredients,
    'steps' => Input::get('recipe')
));

I’ve tried numerous ways and I get errors like the $ingredients array not being defined or not being able to use [] in the variable. I tried defining the variable as an ‘$ingredients = ”;’ variable but that just produced an empty string. My problem must be in the logic.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T19:55:18+00:00Added an answer on June 14, 2026 at 7:55 pm

    Build your select list outside the form for brevity as well as (what I do anyway to keep controllers very slim) send the input to the model all at once.

    $input = Input::all();
    $new = Recipe::create($input);
    

    Build the array for the ingredients elsewhere. In the model (perhaps?):

    $ingredients = array(
    'dbname1' => 'displayname1',
    'dbname2' => 'displayname2'
    );
    

    And display it accordingly, then the form inputs should be sent over with the $input in an array that you can parse and then save to your db.

    Other notes about Blade syntax. I’m not aware of a need to define the array brackets [].

    {{Form::open()}}
    {{Form::label('label1','Display Label 1')}}
    {{Form::text('fieldname1',Input::old('fieldname1'))}}
    

    With your ingredients array already built (your current syntax will produce a dropdown and I assume you want checkboxes)

    {{Form::select('ingredientsFIELDNAME',$ingredients)}}
    {{Form::close()}}
    

    In your Input::all() array your ingredientsFIELDNAME field name will have an array if you’ve built it as checkbox instead of select. Hope this all makes sense.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
i got an object with contents of html markup in it, for example: string
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have thousands of HTML files to process using Groovy/Java and I need to
I need to clean up various Word 'smart' characters in user input, including but
I want to count how many characters a certain string has in PHP, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.