logo
down
shadow

Rails - Retain form values on failed submission. Getting "First argument in form cannot contain nil or be empty&quo


Rails - Retain form values on failed submission. Getting "First argument in form cannot contain nil or be empty&quo

By : user2956977
Date : November 22 2020, 03:03 PM
will help you First Rails question! Loving it so far. :D , change it to
code :
def attempt_signup
    @new_user = User.new(params[:user])
    if @new_user.save
     ....
      .....


Share : facebook icon twitter icon
CodeIgniter: How can I retain values after an invalid form submission?

CodeIgniter: How can I retain values after an invalid form submission?


By : Cyndi Dickerson
Date : March 29 2020, 07:55 AM
it should still fix some issue You can get rid of the error by doing
(isset($gender)&&$gender=='Male'))
How do I modify a Google Form after Form submission? I receive "Failed to edit the form."

How do I modify a Google Form after Form submission? I receive "Failed to edit the form."


By : Zollty
Date : March 29 2020, 07:55 AM
To fix this issue I am convinced that this can not be done using Google Forms.
It can still be done using Google App Scripts to create your own user interfaces and interact with your own data repositories.
How to prevent "confirm form resubmission" popup after failed form submission

How to prevent "confirm form resubmission" popup after failed form submission


By : ulviyya
Date : March 29 2020, 07:55 AM
I wish this helpful for you Trick is to keep form data in a session and populate form type with the data stored in same session for failing forms submissions. Data stays in session until successful form submission.
Full example is here: Preventing 'Confirm form resubmission' dialog in symfony applications
code :
/**
 * @Route("/interest", service="my_test_bundle.controller.interest")
 */
class InterestController
{
    private $formFactory;
    private $router;

    public function __construct(
        FormFactoryInterface $formFactory,
        RouterInterface $router
    ) {
        $this->formFactory = $formFactory;
        $this->router = $router;
    }

    /**
     * @Method({"GET"})
     * @Route("", name="interest_index")
     * @Template()
     *
     * @param Request $request
     *
     * @return array
     */
    public function indexAction(Request $request)
    {
        $form = $this->createForm();

        $session = $request->getSession();
        if ($session->has($this->getFormName())) {
            $request->request->set(
                $this->getFormName(),
                unserialize($session->get($this->getFormName()))
            );
            $request->setMethod('POST');
            $form->handleRequest($request);
        }

        return ['interest_form' => $form->createView()];
    }

    /**
     * @Method({"POST"})
     * @Route("", name="interest_create")
     *
     * @param Request $request
     *
     * @return RedirectResponse
     */
    public function createAction(Request $request)
    {
        $session = $request->getSession();

        $form = $this->createForm();
        $form->handleRequest($request);
        if ($form->isValid()) {
            // Do something with: $form->getData();

            $session->remove($this->getFormName());
            $routeName = 'home_or_success_route';
        } else {
            $session->set(
                $this->getFormName(),
                serialize($request->request->get($this->getFormName()))
            );

            $routeName = 'interest_index';
        }

        return new RedirectResponse($this->router->generate($routeName));
    }

    private function createForm()
    {
        return $this->formFactory->create(
            InterestType::class,
            new Interest(),
            [
                'method' => 'POST',
                'action' => $this->router->generate('interest_create'),
                'attr' => ['id' => $this->getFormName()],
            ]
        );
    }

    private function getFormName()
    {
        return InterestType::NAME;
    }
}
load form using AJAX will loose form and values after a failed submission

load form using AJAX will loose form and values after a failed submission


By : snow_man
Date : March 29 2020, 07:55 AM
hope this fix your issue You have 3 options.
Stop loading the whole form by ajax. Hide it with css and show it if the the conditions are met. If the page is shown after some validation error, just show it (change the css inline or give it a different class) Have a condition and every time the page loads check if it is a first load or if the page is shown after some validation error occured. If the latter is true then load again the form with ajax. This condition can be a hidden field that takes its value from the server and you check it on the client every time you serve the page. The second solution can be done on the server too. Have the condition be checked on the server. If it's a first load, then don't populate the form and let it be populated from ajax as you do now. If it's after a validation error then pre-populate the form. It's just an if/else clause.
Unable to retain values in form after unsuccessful submission of form in codeigniter

Unable to retain values in form after unsuccessful submission of form in codeigniter


By : hegang
Date : March 29 2020, 07:55 AM
may help you . Your view file's code is absolutely correct. You only need to few modifications in your controller's method.
There few key points you need to know before implementing solution in your code:
code :
public function add()
{
    $this->form_validation->set_rules('contactno', 'Contact Number', 'trim|is_unique[student.contactno]');
    if ($this->form_validation->run() !== FALSE) {
        // Your database or model function calling will be coded here and make sure it returns boolean value
        if ($isTrue) {
 $this->session->set_flashdata('req_msg', 'Congrats! You have successfully submitted data');
 redirect('student/data/'.$studentid);
        }else{

           // Handle error logs here
         }
    }
    $this->load->view('your_view', $this->view_data);
}
Related Posts Related Posts :
  • Rails 5 - Saving the absolute current url via a button to a cookie?
  • How can / should I override the `build` method for a my model?
  • Install Rails Failed on OSX 10.8.4
  • ruby on rails - undefined method valid?
  • Users Registration on POST
  • Rails application variables in carrierwave store_dir
  • How to customize simple_form for json nested hash
  • Couldn't find file 'jquery', Sprockets::FileNotFound in StaticPages#home error
  • How should I use the alias_method_chain for the build method?
  • how to create two custom registration forms in devise?
  • Rails 4 link_to Destroy not working in Getting Started tutorial
  • How does ruby on rails dynamically define `find_by_id`, `find_by_name` methods?
  • JBuilder dynamic keys for model attributes
  • `initialize': No such file or directory - getaddrinfo (Errno::ENOENT) when Rails new app
  • What is the Ruby equivalent of Node.js' socket.io?
  • Where rails store standard helpers?
  • how to check expected result matches any of give values in rspec?
  • Form submission to create multiple objects
  • Simple Twitter Login with Rails and Email confirmation
  • Where should helpful functions for my controller go in Rails?
  • Using session variable in the Model or the other way
  • Why can't I have ruby code and comments in Embedded Ruby?
  • Rails: How can I make an object available in all views?
  • Cannot enter simply form information into SQLite DB (Rails)
  • How to handle STI and build related models automatically?
  • Suppress an error when saving a record in Rails
  • Rails AJAX reload the page. Why?
  • How to pass user attributes to action mailer
  • Custom Validator to Prevent an appointment from being scheduled too early in day?
  • Postgres Enable TCP/IP Connection
  • How do I avoid the circular argument reference warning in activesupport
  • Unable to push to heroku master because of rails/spring version error
  • deep nested routes in rails
  • Best approach to Users Profile Images in Rails App
  • RailsInstaller: Can I maintain the gem fold when re-installing a new version?
  • couldn't find file 'jquery-ui' i get this error even after having this file in my application.js
  • Ruby regex to split user and date text input
  • Tool like BetterErrors for JRuby?
  • redirect_to in action destroy ruby on rails
  • Where are the I18n.t link and reference paths?
  • Sending emails to multiple recipients in rails app
  • Rails, Devise, Sign up = write name in other Database
  • pass custom attribute on rspec factory_girl controller test
  • rails generate uses wrong version of Ruby
  • Duplicate Requests from a Browser
  • One action in Rails controller sends no data back
  • Local data (JSON) in Middleman inside a different path than /data
  • How to pass numbers in an array into a SQL statement
  • ActiveAdmin - Allow non-logged-in users to view but not edit resources
  • How to refactor this Model logic in Rails
  • :readonly key of belongs_to method doesn't work
  • Create a new view in directory
  • nested resources in devise
  • Yaml value with a leading `!`
  • Rails admin show username instead of User #5
  • Can't start WEBrick with Byebug on
  • Failing Rspec test of a FactoryGirl object
  • engine yard No application found matching remotes:
  • Rails 4 sessions cookie is not set
  • How do I flush a class method in Rails 4 using memcached?
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org