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

Cannot submit custom form #44

Open
andriusign opened this issue Dec 20, 2020 · 12 comments
Open

Cannot submit custom form #44

andriusign opened this issue Dec 20, 2020 · 12 comments

Comments

@andriusign
Copy link

andriusign commented Dec 20, 2020

Hello. I want to make a custom form to submit a comment for an article, and not to use {{ boltform('myForm') }} in order to pass some additional fields (author, articleId) that point to record relations.

I have the following code:
bolt-boltforms.yaml

commentForm:
   submission:
       ajax: false                   # Use AJAX for form submission and handling
   notification:
       enabled: false
       debug: false
       debug_address: [email protected] # Email address used when debug mode is enabled
       debug_smtp: true
       subject: "[TESTING] A showcase form was just submitted"
       from_name: name               # A field name, specified in the fields: section below
       replyto_email: email          # A field name, specified in the fields: section below
       replyto_name: name            # A field name, specified in the fields: section below
       from_email: email             # A field name, specified in the fields: section below
       to_name: My Site              # Must be valid text
       to_email: [email protected] # Must be valid email address
       cc_name: Info Person
       cc_email: [email protected]
       bcc_name: Manager Person
       bcc_email: [email protected]
       attach_files: false
#    templates:                      # Override the global Twig templates for this form
#        form: "@boltforms/form.twig"
#        email: "@boltforms/email.twig"
#        subject: "@boltforms/subject.twig"
#        files: "@boltforms/file_browser.twig"
   feedback:
       success: Form submission sucessful
       error: There are errors in the form, please fix before trying to resubmit
       redirect:
           target: page/another-page  # A page path, or URL
           query: [ name, email ]     # Optional keys for the GET parameters
   database:
       contenttype:
          name: comment  # ContentType record to create
          field_map:
            #   email: 'email'               # Do not try to save this field to the ContentType
            #   content: 'content' # Form field "message" will be saved to the ContentType field "sent_message"
              article_id: 'article_id'
              username: 'username'
              url: ~
              attachments: ~
              string_city_processor_string: ~
            #   path: ~
            #   timestamp: ~
            #   ip: ~

       table: bolt_secret_table    # Specific database table to write to
#    uploads:
    #    subdirectory: showcase_files # The (optional) subdirectory for uploaded files
   recaptcha: false    # This setting is optional to use the overall default, false is the only valid value to disable for this form only.
   fields:
       content:
           type: textarea
           options:
               required: true
               label: Your message
               attr:
                #    placeholder: Well, the other day I was thinking that maybe you ought to improve your website by adding...
                   class: myclass-message
       username:
            type: text
            options:
                required: true
       article_id:
            type: text
            options:
                required: true
       hcaptcha:
           type: captcha
           options:
               captcha_type: hcaptcha
       recaptcha_v3:
           type: captcha
           options:
               captcha_type: recaptcha_v3
       recaptcha_v2:
           type: captcha
           options:
               captcha_type: recaptcha_v2
               # To not show a label at all, use "label: false"
               label: Please complete this CAPTCHA
       recaptcha_v2_invisible:
           type: captcha
           options:
               captcha_type: recaptcha_v2
               captcha_invisible: true
       submit:
           type: submit
           options:
               label: Submit my message »
               attr:
                   class: button primary

article.twig

<section class="comments">
		<header class="comments__header">
			<h2 class="heading">Comments</h2>

			{% if user %}
				<div class="comments__new">
					{% include "partials/comment/_comment_new.twig" with {"articleId": article.id} %}
				</div>

			{% else %}
				<div class="comments__login">
					<span>Login to comment</span>
					{{ login_form() }}
				</div>
			{% endif %}
		</header>

		<hr/>

		<div class="comments__list">
			{% setcontent comments = "comments" where { path: app.request.pathInfo } order "-publishedAt" %}
			{% for comment in comments %}
				{% include "partials/comment/_comment.twig" with {"commentInfo": comment} %}
			{% endfor %}
		</div>
	</section>

_comment_new.twig

{% if articleId is defined %}
	{{ boltform('commentForm') }}

	<form name="commentForm" class="form" method="post">
		<div class="form__group">
			<label class="form__label" for="content">Rašyti naują komentarą</label>
			<textarea id="content" cols="51" rows="3" name="commentForm[content]" class="form__input" required></textarea>
		</div>

		<input type="hidden" name="commentForm[_token]" value="{{csrf_token('commentForm')}}">

		<input type="hidden" name="commentForm[username]" value="{{user.username}}">
		<input type="hidden" name="commentForm[article_id]" value="{{articleId}}">
		<input type="hidden" name="commentForm[string_city_processor_string]">

		<div class="form__group">
			<input class="button" name="commentForm[submit]" type="submit" value="Rašyti">
		</div>
	</form>
{% endif %}

Unless I put {{ boltform('commentForm') }} above

element, this form does not work. I prefer to make my custom form instead of using shortcode to insert it.

If I put {{ boltform('commentForm') }} above my form, when submitting it I get an error:
HTTP 500 Internal Server Error
Call to a member function sanitise() on null
But after hitting enter in URL, page is reloaded and record saved.

Not sure where the bug is. Would be thankful for any insights.

@bobdenotter
Copy link
Member

Hi, what is the exact error message you're getting? I'm assuming you get the "red screen of death", right? Otherwise, set env=dev in your .env to enable debug mode.

@andriusign
Copy link
Author

andriusign commented Dec 23, 2020

Thanks for getting back. I have updated the original question. In my .env file I have:

APP_ENV=dev
APP_DEBUG=1

Dump info

Extension.php line 32
"Submitted form data was logged in the System log."
Extension.php line 32
"Form "commentForm" has been submitted"
Extension.php line 32
Tightenco\Collect\Support\Collection {#3189 ▼
  #items: array:6 [▼
    "submission" => array:1 [▼
      "ajax" => false
    ]
    "notification" => array:16 [▶]
    "feedback" => array:3 [▶]
    "database" => array:2 [▶]
    "recaptcha" => false
    "fields" => array:8 [▼
      "content" => array:2 [▶]
      "username" => array:2 [▶]
      "article_id" => array:2 [▶]
      "hcaptcha" => array:2 [▶]
      "recaptcha_v3" => array:2 [▶]
      "recaptcha_v2" => array:2 [▶]
      "recaptcha_v2_invisible" => array:2 [▶]
      "submit" => array:2 [▶]
    ]
  ]
}
Extension.php line 32
Symfony\Component\Form\Form {#3261 ▼
  -config: Symfony\Component\Form\FormBuilder {#3262 ▶}
  -parent: null
  -children: Symfony\Component\Form\Util\OrderedHashMap {#3263 ▼
    -elements: array:5 [▼
      "content" => Symfony\Component\Form\Form {#3264 ▶}
      "username" => Symfony\Component\Form\Form {#3267 ▶}
      "article_id" => Symfony\Component\Form\Form {#3270 ▶}
      "submit" => Symfony\Component\Form\SubmitButton {#3273 ▶}
      "string_city_processor_string" => Symfony\Component\Form\Form {#3275 ▶}
    ]
    -orderedKeys: array:5 [▶]
    -managedCursors: []
  }
  -errors: []
  -submitted: true
  -clickedButton: Symfony\Component\Form\SubmitButton {#3273 ▶}
  -modelData: array:4 [▶]
  -normData: array:4 [▶]
  -viewData: array:4 [▶]
  -extraData: []
  -transformationFailure: null
  -defaultDataSet: true
  -lockSetData: false
  -name: "commentForm"
  -inheritData: false
  -propertyPath: null
}

Red screen error is:
Call to a member function sanitise() on null

Not a lot of usefull info there but found 
echo twig_escape_filter($this->env, twig_get_attribute($this->env, $this->source, twig_get_attribute($this->env, $this->source, (isset($context["commentInfo"]) || array_key_exists("commentInfo", $context) ? $context["commentInfo"] : (function () { throw new RuntimeError('Variable "commentInfo" does not exist.', 7, $this->source); })()), "timestamp", [], "any", false, false, false, 7), "date", [], "any", false, false, false, 7), "html", null, true);

in var/cache/dev/twig/b4/b4bf65673e8d48cfd0be98a711189f44c25d8d79a65b5b1cddb7f0391eacee4c.php twig_get_attribute (line 50)

If I comment out this

		<div class="comments__list">
			{% setcontent comments = "comments" where { path: app.request.pathInfo } order "-publishedAt" %}
			{% for comment in comments %}
				{% include "partials/comment/_comment.twig" with {"commentInfo": comment} %}
			{% endfor %}
		</div>

from article.twig, I don't see red error screen with "Call to a member function sanitise() on null" error anymore when submitting the form.
If I remove shortcode
{{ boltform('commentForm') }}
, my custom form is not submitting though. The reason I need custom for is that my comments have related fields like username and articleId, so I need to pass them as hidden, which does not seem to be possible while using boltform('commentForm') fn.

@bobdenotter
Copy link
Member

Maybe the information is not useful to you, but it might hold a clue for us. Please make a full screenshot of the error screen.

@andriusign
Copy link
Author

@andriusign andriusign changed the title Cannot submit form Cannot submit custom form Dec 23, 2020
@bobdenotter
Copy link
Member

Are you getting the error on POST'ing only, or also when reloading the page later?

I'm not sure what causes this. What i'd try to do, is maybe make a really simple contenttype with literally only a type: textarea field with name content.

Then, simplify your form and only store that one field. If that works, add the fields one by one, pinpointing where it breaks.

username and articleId, so I need to pass them as hidden, which does not seem to be possible while using
boltform('commentForm') fn.

Is that so? I think type: hidden is supported in boltforms, right?

@andriusign
Copy link
Author

I only get that error when posting, not reloading.

I made my form to only have content textarea and there is still the same error. Not I get the same error despite where I submit form: via shortcode or via custom. I bet It has to do something with displaying comment list below, because when I comment it out, no error.

Regarding hidden input in boltform, I am not sure whether it is possible to set its value to something related to the current post being displayed. Does this have to be done in config?

I am also not sure why this is needed "string_city_processor_string" or "table: bolt_secret_table" if I am storing a contenttype.

@bobdenotter
Copy link
Member

I made my form to only have content textarea and there is still the same error. Not I get the same error despite where I submit form: via shortcode or via custom. I bet It has to do something with displaying comment list below, because when I comment it out, no error.

That's what i was trying to get at: Is it breaking when adding something, or when retrieving it.. If you comment out the "displaying the comments", does it then work?

@andriusign
Copy link
Author

andriusign commented Dec 23, 2020

Yes, If I comment out displaying comments bellow, it works, but only if "{{ boltform('commentForm') }}" is present.

@andriusign
Copy link
Author

Any clue what might be wrong here?

@jlgranda
Copy link

I only get that error when posting, not reloading.

I made my form to only have content textarea and there is still the same error. Not I get the same error despite where I submit form: via shortcode or via custom. I bet It has to do something with displaying comment list below, because when I comment it out, no error.

Regarding hidden input in boltform, I am not sure whether it is possible to set its value to something related to the current post being displayed. Does this have to be done in config?

I am also not sure why this is needed "string_city_processor_string" or "table: bolt_secret_table" if I am storing a contenttype.

I get bolt forms last_processor_contact_domain too. Why Bolt Forms add this "extra" fields?

@Spidlace
Copy link

Hi !

Maybe related to this issue ?
bolt/common#37

I see you are using :

from_name: name               # A field name, specified in the fields: section below
replyto_email: email          # A field name, specified in the fields: section below
replyto_name: name            # A field name, specified in the fields: section below
from_email: email 

But actually it's not working
Problem with regex, I proposed an pull request

@AndreyChursin
Copy link

Oh ho ho :-(
I get bolt forms "string_city_processor_string" visible field too.

I have described form config in ~/config/extensions/bolt-boltforms/myform.yaml
and there no word about "city" or other things...

Why Bolt Forms allowed to add this "extra" visible field and how I can fix it?

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

5 participants