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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:56:57+00:00 2026-05-20T10:56:57+00:00

When you create a form element with CakePHP like so: echo $this->Form->input(‘User.first_name’); You start

  • 0

When you create a form element with CakePHP like so:

echo $this->Form->input('User.first_name');

You start with a blank field. When you put in your name John and submit the form, if the form does not validate, the name John is still there when you return to the page to fix your validation errors. This is convenient because you can fix your mistakes without having to retype the parts you got right.

How does it get put back as the value?

I need to know this because once the form is submitted successfully and you leave the page and come back the form is blank again.

I am saving the name as a session so I can do this instead:

$first_name = $this->Session->read('Cart.User.first_name');
echo $this->Form->input('User.first_name',array('value'=>$first_name));

Now if you lave the page and come back, the name will still be there but that breaks the original logic preventing it from putting what you type back in when the form fails to validate.


Let me give you an example.

I am creating my name element like:

$first_name = $this->Session->read('Cart.User.first_name');
echo $this->Form->input('User.first_name',array('value'=>$first_name));

I fill out the form correctly and am taken to a final checkout page. I see that I misspelled my name as Jhon. So I clicked the edit button and am taken back to the form, since I manually set the value in my form my data is all still there. I correctly retype my name as John and submit the form. For some other reason the form did not validate and I am taken back to the form, but instead of displaying John like it originally would, it now displays Jhon again because when I manually set value I am overriding the default with whatever is still in the session.

So if I know how CakePHP puts the data back in the form when it does not validate, I can put the session data back in the same way without overriding the default.

  • 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-05-20T10:56:57+00:00Added an answer on May 20, 2026 at 10:56 am

    The data is passed back to the form in a POST data call. The FormHelper auto-magic elements use that data to populate the value attributes of the fields. If you leave the page, the post information doesn’t get passed along.

    You will need to save $this-data block in a session value to keep it while moving from page to page.

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

Sidebar

Related Questions

Using Zend_Form, how would I create form elements like this: <input type=text name=element[1] value=
I want to create a form element that gonna output like this select date:
Using CakePHP, I created select-option form element with: echo $form->select('items', $numeration , array('selected' =>
I need to create a form element <input disabled type=text value=Shui Mu Tsinghua />
How can I create Zend Form Element implements A html tag not INPUT. I
I am trying to create a form in Rails 2.2.2 that populates a field
How can I dynamically create a form element and provide it with dynamically incremented
Using CakePHP 1.3 , I post a form which correctly fills in $this->data .
I'm trying to dynamically add elements to a Cakephp form: <?php echo $javascript->link('jquery',false); ?>
I would like to create a jQuery function that I can attach to form

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.