cppcms icon indicating copy to clipboard operation
cppcms copied to clipboard

Problem to customize a form

Open pcouderc12 opened this issue 6 years ago • 5 comments

My form is ok with: <form class="form-signin" method="post" action="" ><% csrf %> <% form as_p mydata %> </form> But when I try: <form class="form-signin" method="post" action="" ><% csrf %> <input type="email" name="<%= mydata.email()%>" > ... </form>

I get a compile error. Is ther an exmple of this case in the documentation ? I have found none. What am I missing ? Thank you for cppcms. PC

pcouderc12 avatar Apr 12 '19 10:04 pcouderc12

I get a compile error.

What error? Without details it is hard to answer

artyom-beilis avatar Apr 12 '19 14:04 artyom-beilis

Sure ! (I though the error was trivial in my line...) output:

templates/login_login.tmpl: In member function ‘virtual void myskin::login_login::page_content()’: templates/login_login.tmpl:13:54: error: no match for call to ‘(cppcms::widgets::email) ()’ <input type="email" id="inputEmail" name="<%= data.email()%>" class="form-control" placeholder="Email address" required autofocus>
and content.h :

`struct login_login_form : public cppcms::form { cppcms::widgets::email email; cppcms::widgets::password password; cppcms::widgets::submit submit; login_login_form() { email.message("votre email"); password.message("votre password"); add(email); add(password); add(submit); } virtual bool validate() { if(!form::validate()) return false; return true; } }; struct login_login : public master { std::string name,email,password; login_login_form data; };

`

pcouderc12 avatar Apr 12 '19 18:04 pcouderc12

Does adding a space between ) and % to make email()% become email() % help?

masaoliou avatar Apr 15 '19 06:04 masaoliou

No. The generatedcode is : out()<<cppcms::filters::escape(content.data.email());

pcouderc12 avatar Apr 15 '19 09:04 pcouderc12

Quick recap to see if I got your problem:

The offending template line is:

<input type="email" id="inputEmail" name="<%= data.email()%>" class="form-control" placeholder="Email address" required autofocus>

The generated C++ Code is:

out()<<cppcms::filters::escape(content.data.email());

And content is of type login_login, so content.data is of type login_login_form.

This means content.data.email() is trying to call cppcms::widgets::email::operator() (which I believe to be nonexistant, hence no match for call to ‘(cppcms::widgets::email) ()’.

Try changing

<input type="email" id="inputEmail" name="<%= data.email()%>" class="form-control" placeholder="Email address" required autofocus>

to

<input type="email" id="inputEmail" name="<%= data.email.value()%>" class="form-control" placeholder="Email address" required autofocus>

idkCpp avatar May 04 '19 10:05 idkCpp