1

I've a form which shown from values in the database.

Now next day user fills it in and submits it. But the underlying data has already changed in the database.

I can see that in the validation handler form_state contains data from the form prepared after it is submitted but which contains updated values from other users, while the data submitted by the user is based on 1 day old data and he/she is not aware of changed data.

How does Drupal form behave in the scenario?

For example:

  1. I load a form and I see one row of data
  2. Another user comes and adds a new row of data
  3. I submit 1 row of data I see after checking on the checkbox
  4. FAPI now rebuilds the form but it now finds two rows instead of one
  5. In validation handler it sees two rows of data(but I submitted seeing single row)

→ Assume each row is 1 checkbox + textfield

Now I want to give error and ask the user to reload the form and submit again

0

If you include a function myform_validate, you can test the value in the $formstate array against a query for the current value in the database. IF they do not match, return false and the original form will be redisplayed. This is explained in greater detail in the documentation for the form api

  • No, $form and $form_state both contain latest values from database. – AgA Jan 10 '12 at 17:05
  • I guess I don't understand your question. Please edit your question to express a question. – Ashlar Jan 10 '12 at 19:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.