Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem to customize a form #56

Open
pcouderc12 opened this issue Apr 12, 2019 · 5 comments
Open

Problem to customize a form #56

pcouderc12 opened this issue Apr 12, 2019 · 5 comments

Comments

@pcouderc12
Copy link

pcouderc12 commented Apr 12, 2019

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

@artyom-beilis
Copy link
Owner

I get a compile error.

What error? Without details it is hard to answer

@pcouderc12
Copy link
Author

pcouderc12 commented Apr 12, 2019

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

`

@masaoliou
Copy link

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

@pcouderc12
Copy link
Author

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

@idkCpp
Copy link

idkCpp commented May 4, 2019

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>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants