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 8297721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T15:31:08+00:00 2026-06-08T15:31:08+00:00

all creating a cakephp(using 2.1.2) page. we prompt the user to enter how many

  • 0

all creating a cakephp(using 2.1.2) page. we prompt the user to enter how many fields they are after(an int) and then we want the page to use a for-loop for the number entered.

here is the code for the add page

<h2>Please select how many fields you wish to add</h2></br>


<?php
print $this->Session->flash('flash', array('element' => 'alert'));

echo $this->Form->create('Field', array('action'=>'add'));

For(int i=0; i<'flash'; i++)
{
echo $this->Form->input('name',array('label'=>'Please Enter Field Name: ', 'type'=>'text')); 
echo $this->Form->input('description',array('label'=>'Please Enter Field Description: ', 'type'=>'text')); 
}
echo $this->Form->end('Click Here To Submit Template');

?>

here is the code for the alert

<script type="text/javascript">
    prompt('How many fields?','<?php print $message; ?>');
</script>

the question is how do we create a variable with the alert.ctp then be able to use that variable for a for loop to print out a form that takes user input.

EDIT:

Javascript function:

<script type="text/javascript">

var number_of_fields=prompt("How many fields?",'<?php print $message; ?>');
var field_html="";
for (i=0; i<number_of_fields; i++)
{
  field_html +='<input type="text" name="data[FIELD]['+i+'][name]">';
}
$("#FORMID").append(field_html); 

</script>

View:

<?php
print $this->Session->flash('flash', array('element' => 'alert'));

echo $this->Form->create('Field', array('action'=>'add'));



echo $this->Form->end('Click Here To Submit Template');

?>

Get no errors now, but cant display any fields. What do we put in the view to print the fields (which will be more input- so user can create a field)?

  • 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-08T15:31:10+00:00Added an answer on June 8, 2026 at 3:31 pm

    Since we are getting the value of no: of required in javascript , i recommend to create fields also in javascript by following conventions used by cakephp to create input fields. So you can use javascript for loop and concat the fields in to a js variable and insert this html inputs to the form using javascript.

    eg:

    var number_of_fields=prompt("How many fields?",'<?php print $message; ?>');
    var field_html="";
    for (i=0; i<number_of_fields; i++)
    {
      field_html +='<input type="text" name="data[MODELNAME]['+i+'][name]">';
    }
    $("#FORMID").append(field_html); 
    

    i hope this would make sense

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

Sidebar

Related Questions

I'm using cakephp and would like to display all Submissions which are part of
I'm creating a Q&A application in CakePHP, and I want to exclude my associations
Immediately after creating all the beans declared in the various context files of my
I'm using xCode 4.2, and after creating the .h and .m classes separately, I
Hi all am creating a excel using Microsoft office interop.and it creates files successfully.But
Beyond creating a dll with all the same functions with the same interface and
I am creating a calculator application for all types of mathematical algorithms. However, I
I'm creating a log system ('outside' the application) that logs all the click on
hi all i am declaring id and class when creating table dynamically as below
All my dynamically generated action links etc. are creating links like / A ccount/

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.