Custom Register form not working - html

Hie folks..... When I click on submit button of the CUSTOM REGISTRATION form..... it redirects to the same page...... ?? No idea what this is about......
Controller: default.py
def register():
form=auth.register()
form.add_button('Cancel', URL('register'))
return dict(form=form)
View: register.html
Please take the little pain to open this link to view the html file.... I am unable to post the exact html code in here... problem with syntax..
http://pastebin.com/bPQu2DX3
print form.errors -> Storage {}
print form.accepts(request.vars,session) -> false

You have duplicated line form=auth.register()
You return dict(late=late, form=form) but late is never used in your controller...
I think you should simplify your controller :
def register():
form=auth.register()
form.add_button('Cancel', URL('register'))
return dict(form=form)

First, your first two lines are useless, as the third line simply overwrites the "form" variable with a completely new object. Second, auth.register() already handles the form processing, so you cannot subsequently call form.accepts(). If you want to control the flash messages, use the auth.messages object to set them.

Thanx folks .. Finally got the answer....
I was not putting all the fields in custom form..
the fields that one doesn't require and is validated as not null also needs to be mentioned in custom form as hidden attributes otherwise whole of the form won't get accepted.

Related

How to prevent old data in Model from being passed into the input fields automatically?

Is it possible to prevent the data from being automatically passed to the input fields. For example - if I have an edit page where I want to change the data and I want the user to type the data again without giving him the pre-filled old data. I was looking over some documentation about the ModelState and the asp-for tag but I just couldn't find the answer.
I was looking for help and I found this post here. Well I want to do exactly the opposite.
asp-for tag helper functionality_
EDIT:
I tried to change the value attribute of the input field to empty string and it worked, however I still would like to know if there is an asp.net approach.
If you don't want to pass data from action to Edit view,you can return a view with an empty model like this:
public IActionResult Edit()
{
return View(new YourModel());
}
Or you can try to use id and name attribute to replace asp-for,so that the data will not be binded to inputs.Here is a demo.
Change
<input asp-for="TestProperty" />
to
<input id="TestProperty" name="TestProperty" />

How to add a break after Symfony's formType labels

I have some issues to put a break after my input's labels generated by my Symfony's Form.
Here is the form :
my form
Here is my twig :
my twig
And this is what I have now, I just want to return on the line after each label so my quizz finally looks like a quizz ;) :
what i have
If you know the way to do this...
You should take a look at form_theme and make a custom one.
Did you try calling form_row(form.choix) instead of form_widget(form.choix) ?

table division text dissapears after validation is run on submit

In my razor page I've got several check boxes arranged in a table. I've got some other #Html.EditorFor elements that are required inputs. When I submit, and the validations are run, the page refreshes with the eoor messages and the text next to my check boxes in the table disappears. What's up with that?
My checkboxes are made with #Html.CheckBoxFor
I'm not using any special stylings or class attributes or anything right now.
You are correct. When the form is posted, you will lose all of that data provided you do not resend it back into your view. In your controller, you need to return the model along with the view. Without seeing your code, I can't give a specific answer but it should look something like this:
public ActionResult DoSomethingWithFormPostData(Model yourModel)
{
//Do whatever you need to do.
return PartialView("_yourView", model);
}
Alternatively, I like to have a method in my controllers to I use for the sole purpose of populating a page. If you have something like that, you can refer back to that sending the model as a routevalue in this way:
public ActionResult DoSomethingWithFormPostData(Model yourModel)
{
//Do whatever you need to do.
return RedirectToAction("_yourView", "YourController", model);
}

Custom Input Names on GravityForms

How can I add custom input names to gravity forms? I need to submit a form to a third party service that requires very specific form names.
My current idea is to write a bit of jQuery to dynamically rename everything when the page loads. Obviously this isn't ideal.
Gravity Forms: http://www.gravityforms.com/
After contacting the makers of Gravity Forms, it sounds like they don't support custom input names. As a workaround, I wrote a bit of jQuery to rename inputs with the correct form names. For example:
$("input#input_1_1").attr("name","first_name");
Just put some code in functions.php and fill out the form which will then email you with a list of the id names, they are the same names that you can fine using developer tools etc. This was just faster for me. Then change the code to have it post via curl with different input names.
This uses php so it's on the server to handle. That way you don't have to worry about people with JS disabled in their browser.
http://0to5.com/gravity-forms-submitting-forms-to-3rd-party-applications/
Add a new field (HTML field). In content settings of this field add this javascript with script tags
Non-jquery solution:
document.getElementById("input_14_4").setAttribute("name", "email");
Another solution i found here
https://docs.gravityforms.com/gform_field_content/
add_filter( 'gform_field_content', function ( $field_content, $field , $value, $lead_id, $form_id) {
if ( $form['id'] != 14 ) {
//not the form whose tag you want to change, return the unchanged tag
return $field_content;
}
if ( $field->id == 3 ) {
return preg_replace( "|name='(.*?)'|", "name='email'", $field_content );
}
return $field_content;
}, 10, 5 );

Destroy data based on HTML class name in Rails

I'm building a simple todo list using Rails (3.2.5).
I show all of the users todo items in an unordered list, each list item being the todo itself. By clicking on the todo item the user marks it as completed. Using jQuery I give the li a class of done so I can change its styling. By clicking on a "Clear completed" button I want the completed items to be destroyed (and deleted from the database).
How can this be done?
NB: I'm basically trying to recreate this app using Rails: http://davidpdrsn.com/todos/
You can do it using a remote form
So you would have something like
you would have a form with remote: true for each item or you could have only one form and submit it with JQuery.
class TodoController
def set_completed
#todo = Todo.find(params[:id])
#todo.done = true # you could move this to your model and do something like #todo.done! and that would save it automatically
#todo.save
end
def destroy_completed
#todos_to_delete = Todo.where(done: true)# here you could also move it to your model and do it like Todo.completed
#todos_to_delete.destroy_all
end
end
and you would render the response with the js for formatting, or even removing items on your list, like
views/todo/set_completed.erb.js
$("#item_<%= #todo.id %>").addClass("completed");
Supposing the model is called Todo and the completed column is called completed, you can write one of these in the controller:
Todo.destroy_all(:completed => true)
Todo.where(:completed => true).destroy_all
If you need help with how to manage the ajax request/response, here there is a good start (sorry, I don't want to give you the solution, IMHO you should make your way by yourself)
Resources: ActiveRecord#Base::destroy_all