I am trying to create a form with Craft that allows users to rate entries in a specific section. The section that tracks the ratings has three fields: the ratings drop-down field, a user field, and an entry field. Here is my form right now:
<form method="post" accept-charset="UTF-8">
{{ getCsrfInput() }}
<input type="hidden" name="action" value="entries/saveEntry">
<input type="hidden" name="redirect" value="viewentry/{slug}">
<input type="hidden" name="sectionId" value="userRatings">
<input type="hidden" name="enabled" value="1">
<input type="text" id="user" name="ratings" value="{{currentUser}}" style="display:none;" readonly>
<input type="text" id="restaurant" name="restaurant" value="{{entry.id}}" style="display:none;" readonly>
<label for="ratings">Rate This Restaurant</label>
<select id="ratings" name="ratings" required>
{% for option in entry.ratings.options %}
<option value="{{ option.value }}">{{option.label}}</option>
{% endfor %}
</select>
<input class="button" type="submit" value="Rate">
I have two text boxes that are recording the current user and the Entry ID of the entry I am trying to rate (we are on the _entry.html for this entry). Before I added the "display:none" they were both showing the correct information. Then I am pulling the options for the ratings field that I set in craft and setting them as the values for the drop down here (which is working).
When I try to submit I get a craft error: "Internal Server Error Trying to get property of non-object." Any help or suggestions would be greatly appreciated!
You're missing the 'title' field ..
<input type="hidden" name="title" value="Free Registration Title">
It's a requirement
Related
I have a Wicket page with this structure:
<form wicket:id="generalForm" method="post" class="form_recherche">
<input value="" type="text" wicket:id="myField_1" />
<form wicket:id="innerForm" method="post">
<input value="" type="text" wicket:id="myField_2"/>
<input type="submit" class="button-classic" wicket:id="accept_2"/>
</form>
<input type="submit" class="button-classic" wicket:id="accept_1" />
</form>
1 external form with 1 inner form. One field each. The fact is that when the "accept_2" button is clicked, the field "myField_1" is not submitted to the server (only the "myField_2" is submitted). And in fact, I would need the "field_1" field to do some validation.
What am I missing and why isn't the "myField_1" being filled on the server why "accept_2" is clicked?
You need to override Form#wantSubmitOnNestedFormSubmit() on the outer Form to return true. This way you will tell Wicket that you want the (outer) form to be submitted as well when one of its nested forms is submitted.
You used SO tags wicket-1.5 and wicket-1.6. I am not sure whether this method is available for your version of Wicket.
I have a contact form on my site. I use formit for its FormIT validation. I want email be not more than 40 characters, be reqired and be correct email address. Message field is required too and has max length set.
Validator doesn't work correctly:
When required fields are empty, it shows error message and doesn't allow to send the form (this situation is absolutely correct)
When in email is any text (valid or not), form is sent but redirect to success page doesn't work (so it happens also when we enter more than max length)
[[!FormIt?
&hooks=`spam,email,redirect,FormItAutoResponder`
&emailTpl=`emailTplContact`
&emailSubject=`Message from site.com`
&emailTo=`myemail#gmail.com`
&validate=`email:email:required:maxLength=^40^,
message:required:maxLength=^150^`
&redirectTo=`11`
&fiarTpl=`emailAutoRespond`
&fiarSubject=`Your message is sent`
&fiarFromName=`My Site`
&fiarFrom=`myemail#gmail.com`
&fiarToField=`email`
&fiarReplyTo=`email`
]]
<form id="contact-form" method="post" action="[[~[[*id]]]]" enctype="application/x-www-form-urlencoded" role="form" data-toggle="validator" name="order">
<input type="text" id="name" name="name" type="name" placeholder="Name" value="[[!+fx.name]]" size=25>
<input type="text" required="required" type="email" id="email" name="email" placeholder="Email" value="[[!+fx.email]]">
[[!+fx.error.email]]
<textarea required="required" placeholder="Message" id="message" name="message">[[!+fx.message]]</textarea>
<button name="send">Send</button>
</form>
</div>
You have type attribute twice in the name input and the email input, so that might be the problem.
<input type="text" id="name" name="name" type="name">
<input type="text" required="required" type="email">
Remove type="name" and type="email" -- (leave type="text")
Also - I have only ever used a prefix of fi for Formit placeholders; do you know for sure that fx will work? Did you set that somewhere else? You say you're seeing the error message so I guess the error placeholder must be working...
Be sure to add placeholderPrefix to your FormIt call:
[[!FormIt?
&placeholderPrefix=`fx`
&hooks=`spam,email,redirect,FormItAutoResponder`
&emailTpl=`emailTplContact`
&emailSubject=`Message from site.com`
&emailTo=`myemail#gmail.com`
&validate=`email:email:required:maxLength=^40^,
message:required:maxLength=^150^`
&redirectTo=`11`
&fiarTpl=`emailAutoRespond`
&fiarSubject=`Your message is sent`
&fiarFromName=`My Site`
&fiarFrom=`myemail#gmail.com`
&fiarToField=`email`
&fiarReplyTo=`email`
]]
What I would like to do is make all fields show their validation errors when:
visiting and modifying a field so that its dirty state is triggered (the default), and also
validating and triggering dirty when the submit is pressed
Take the following form
<div ng-form="MyForm">
<label>
<input type="text" name="numbers" ng-required="'true'" ng-pattern="/^[0-9]*$/" ng-model="numbers" />
<span class="error" ng-show="numbers.$error.required">Required</span>
<span class="error" ng-show="numbers.$error.pattern">Pattern</span>
</label>
<label>
<input type="text" name="characters" ng-required="'true'" ng-pattern="/^[a-z]*$/" ng-model="characters" />
<span class="error" ng-show="characters.$error.required">Required</span>
<span class="error" ng-show="characters.$error.required">Pattern</span>
</label>
<button ng-click="validateAndSubmit()">Submit</button>
</div>
Essentially, I would like to create a directive that validates (sets dirty to true) for all the controls in an arbitrary form. Is there a simple way to get the form controls from the FormController without finding the actual dom elements?
I have a content type which is only viewable (not editable) to a certain role. I've customised the form output completely (manually outputting each field as they display in a certain way).
However there's one field I would like this user to be able to 'edit' which is a custom 'revision comment' field I've made. I can hardcode in the form fields, except of course it won't work without the token, build id etc that Drupal generates like this:
<input type="hidden" name="form_build_id" value="<?php print render($form['#build_id']); ?>">
<input type="hidden" name="form_token" value="<?php print drupal_get_token($form['#token']); ?>">
<input type="hidden" name="form_id" value="<?php print render($form['#form_id']); ?>">
So essentially I'm wondering what workaround I could use, as $form and it's variable are obviously only generated when 'editing' the node.
In case anyone else needs to know, I hardcoded this into the template file and it works:
<form class="node-form node-project-form" action="/dashboard" method="post" id="project-node-form" accept-charset="UTF-8">
<input type="hidden" name="nid" value="<?php print $nodeid; ?>">
<input type="hidden" name="uid" value="<?php print $user->uid; ?>">
<div id="revision-comments" style="margin:0">
<label for="log-comments">Log Message</label>
<textarea id="log-comments" name="log_comments"" cols="60" rows="4" class="form-textarea"></textarea>
</div>
<input type="submit" id="edit-submit" name="op" value="Post Comment" class="form-submit">
</form>
i found a strange behavior in my JSP site and hope somebody have a good advice for me:
JSP-Code:
<c:forEach items="${info.moneyList}" var="mmRoles" varStatus="uStatus" >
....
<div class="paperback" id="delete_${uStatus.index}">
<form id="deleteMoneyMarketSpread_${uStatus.index}"
action="deleteMoneyMarketSpread" method="post">
<input type="hidden" name="currency"
value="${mmRoles.currency}" />
<input type="hidden" name="loan"
value="${mmRoles.loan}" />
<input type="hidden" name="lcfspread"
value="${mmRoles.lcfspread}" />
</form>
</div>
....
</c:forEach>
I generate a form element with hidden input fields in a forEach loop. The interesting point is that (only) in the first iteration no form element will be created. When i check the HTML code with Firebug i only find the hidden input fields, but no surrounding form tag.
HTML code:
<!-- first iteration -->
<div id="delete_0" class="paperback">
<input type="hidden" value="EUR" name="currency">
<input type="hidden" value="true" name="loan">
<input type="hidden" value="123.0" name="lcfspread">
</div>
...
<!-- second iteration -->
<div id="delete_1" class="paperback">
<form id="deleteMoneyMarketSpread_1" method="post" action="deleteMoneyMarketSpread">
<input type="hidden" value="FGH" name="currency">
<input type="hidden" value="true" name="loan">
<input type="hidden" value="1.0" name="lcfspread">
</form>
</div>
Have anyone an idea why this happens?
Regards
Sascha
I still don't found a solution or a reason for this so i used a workaround an create my Form on demand with javaScript when clicking the icon. Not the best way but it works.