artyom-beilis/cppcms

Problem to customize a form

Opened this issue · 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

I get a compile error.

What error? Without details it is hard to answer

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;
};

`

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

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

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>