ExpressionEngine SafeCracker Form Does Not Submit and Simply Refreshes Page - expressionengine

I have the following contact form, but it does not seem to be submitting when I have completed all of the fields as required. The page just refreshes to show the same form with the data filled in.
{exp:safecracker channel="contact_us" id="form-contact" return="contact-us/thanks" datepicker="no" error_handling="inline" include_jquery="no" rules:cf_contact_us_email="valid_email"}
<fieldset>
<legend>Your contact details</legend>
<ul>
<li><label>{label:cf_contact_us_title}</label>{field:cf_contact_us_title}{if required} *{/if}</li>
{if error:cf_contact_us_title}<li class="error">{error:cf_contact_us_title}</li>{/if}
<li><label>{label:cf_contact_us_name}</label>{field:cf_contact_us_name}{if required} *{/if}</li>
{if error:cf_contact_us_name}<li class="error">{error:cf_contact_us_name}</li>{/if}
<li><label>{label:cf_contact_us_address}</label>{field:cf_contact_us_address}{if required} *{/if}</li>
{if error:cf_contact_us_address}<li class="error">{error:cf_contact_us_address}</li>{/if}
<li><label>{label:cf_contact_us_towncity}</label>{field:cf_contact_us_towncity}{if required} *{/if}</li>
{if error:cf_contact_us_towncity}<li class="error">{error:cf_contact_us_towncity}</li>{/if}
<li><label>{label:cf_contact_us_postcode}</label>{field:cf_contact_us_postcode}{if required} *{/if}</li>
{if error:cf_contact_us_postcode}<li class="error">{error:cf_contact_us_postcode}</li>{/if}
<li><label>{label:cf_contact_us_telephone}</label>{field:cf_contact_us_telephone}{if required} *{/if}</li>
{if error:cf_contact_us_telephone}<li class="error">{error:cf_contact_us_telephone}</li>{/if}
<li><label>{label:cf_contact_us_email}</label>{field:cf_contact_us_email}{if required} *{/if}</li>
{if error:cf_contact_us_email}<li class="error">{error:cf_contact_us_email}</li>{/if}
<li class="inset"><label>{label:cf_contact_us_method}</label></li>
<li>{field:cf_contact_us_method}{if required} *{/if}<br>{error:cf_contact_us_method}</li>
{if error:cf_contact_us_method}<li class="error">{error:cf_contact_us_method}</li>{/if}
<li><label>{label:cf_contact_us_enquiry}</label>{field:cf_contact_us_enquiry}{if required} *{/if}</li>
{if error:cf_contact_us_enquiry}<li class="error">{error:cf_contact_us_enquiry}</li>{/if}
<li class="checkbox-first">{field:cf_contact_us_terms} Terms and Conditions{if required} *{/if}</li>
{if error:cf_contact_us_terms}<li class="error">{error:cf_contact_us_terms}</li>{/if}
<span class="clearfix"></span>
<li class="form-button"><input type="submit" class="submit rounded" name="send" value="Send" /></li>
</ul>
</fieldset>
{/exp:safecracker}
I wondered if anyone might be able to help me figure this out. It’s likely something incredibly obvious.

Try removing the error_handling="inline" parameter, which will allow you to see the actual error message(s) SafeCracker is presenting to you thru the User Message Templates.
In looking over your code, your SafeCracker form seems to be missing the Title {title} field, which I believe is required by SafeCracker — either thru a hidden input or supplied by the user.
To troubleshoot your SafeCracker form:
Remove the Error Handling Parameter
Include the Entry Title Field {title}
Doing this will allow you to:
See the Full Error Message
Submit the Entry to ExpressionEngine
Once you have everything working, you can change the error handling parameter back to inline.

Related

Node parse data from one view to another

Let's say I have one view
users.handlebars
{{#each users}}
<tr>
<td>{{this.id}}</td>
<td>{{this.profile.firstname}}</td>
<td>{{this.profile.lastname}}</td>
<td>{{this.profile.location}}</td>
<td>{{this.email}}</td>
<td>{{this.profile.status}}</td>
<td><i class="fas fa-user-edit"></i>
<a class="user-ban-btn" href="javascript:void(0)">
<i class="fas fa-hand-paper"></i>
</a>
<a class="user-delete-btn" href="javascript:void(0)"> // THIS IS DELETE BUTTTON
<i class="fas fa-trash"></i>
</a>
</td>
</tr>
{{/each}}
And another
main.handlebars
<div class="modal-box" id="user-delete-modal">
<div class="modal-box-message">
<p>Are you sure u want to delete this user?</p>
YES
NO
</div>
</div>
In first view, I click on button delete user but I need to parse data from this view to the second view where I choose YES or NO because yes have a link with ID parameter /users/delete/:id But i don't know to do it.
Note: Main.handlebars is template and users.handlebars is inserted into this template and that modal box is opened just with javascript there is no page refresh.
I will be thankful for any idea how to make it.
Solved by adding onClick="get_user_id(this.id)" to a element.
And then taking it with javascript.

How to get data from a form dropdown select element?

I'm using Express.js and trying to get form data of a dropdown select element,
I tried with body-parser but what I get with eq.body.method_select is undefined.
I didn't find much info about how to do this on the web.
Here is my code html code:
<form action="url_analyse">
<div class="col-lg-6">
<div class="input-group">
<select class="custom-select mb-2 mr-sm-2 mb-sm-0" name="method_select" id="inlineFormCustomSelect">
<option value="5">Regular Search (Short)</option>
<option value="10">Intense Search (Long)</option>
<option value="20">Deep Search (Very Long)</option>
</select>
<input type="text" name="url_input" class="form-control" placeholder="Enter URL">
<span class="input-group-btn">
<button class="btn btn-secondary">Go!</button>
</span>
</div>
</div>
Here is my js code:
app.get('/url_analyse', function(req, res) {
console.log(req.body.method_select);
})
Hope you can help me with that.
Thank you.
There are two issues here:
You might want to explicitly add the leading forward slash: action="/url_analyse"
The default form submission HTTP method is GET, which means that form fields will be passed in the query string portion of the URL. This means you will instead need to access req.query to get at the form fields. You only need body-parser and req.body when you use POST and other methods (with the appropriate enctype) to submit your form.

How to show a message if there are no products inside a category with exp:resso store plugin?

I'm using the latest version of EE2 and a plugin called Exp:resso store.
I have products assigned to a category and for the most part all of this is working fine. Below is my code:
<div class="col-md-7">
{exp:channel:categories channel="products" style="linear"}
<section class="section accordion repeater">
<h3>
{category_name}
<div class="icon">
<img src="/assets/local/img/plus-icon.jpg" alt="">
</div>
</h3>
<div class="accordion-content">
{exp:store:search orderby="title" sort="asc" category="{category_id}"}
{exp:store:product entry_id="{entry_id}"}
<p class="accordion-download">
{title} - {price}
<span><img src="/assets/local/img/add-to-cart.jpg" alt="">Add to cart</span>
</p>
{/exp:store:product}
{/exp:store:search}
</div>
</section>
{/exp:channel:categories}
</div>
I'm trying to find a way to show a No products exist message if the category doesn't have anything inside of it. I've tried using {count}, {total_results} & {total_rows} to check if there aren't any products. Problem is everything I try is obviously wrong because nothing gets output :/
Thanks in advance
The store search tag is a wrapper for the channel entries tag pair so you would need to use the {if no_results} tag pair.
<div class="col-md-7">
{exp:channel:categories channel="products" style="linear"}
<section class="section accordion repeater">
<h3>
{category_name}
<div class="icon">
<img src="/assets/local/img/plus-icon.jpg" alt="">
</div>
</h3>
<div class="accordion-content">
{exp:store:search orderby="title" sort="asc" category="{category_id}"}
{exp:store:product entry_id="{entry_id}"}
<p class="accordion-download">
{title} - {price}
<span><img src="/assets/local/img/add-to-cart.jpg" alt="">Add to cart</span>
</p>
{/exp:store:product}
{if no_results}
There are no products
{/if}
{/exp:store:search}
</div>
</section>
{/exp:channel:categories}
</div>
Should also be mentioned if you are not creating a form for the to add the products to the cart you could use the {store_field_short_name:price} variable to reduce the number of queries on your page. Most store things such as sku, weight, measurements can all be access by using the field short name followed by :variable

ExpressionEngine: Multiple channels issue with custom URL's

On this page:
http://build.jhousemedia3.com/pleasanton/shop/district-profile/stoneridge-shopping-center/
The URL is formatted like so
http://build.jhousemedia3.com/pleasanton/[channel]/[template]/[query parameter]
I'm running an exp:channel:entries query using the last segment of the URL (segment_4)
What's happening is that when I run it from this URL I can't pull in data from any other channel except the specific shopping districts channel. If I were to change that last segment to /?id=28 (or something similar) I can pull data from multiple channels.
Any ideas?
Code for pulling the profile of a shopping district based on the URL:
{exp:channel:entries url_title="{segment_4}" limit="1" channel="shopping_districts"}
<h2 class="upper"><span class="greenlight">{title}</span></h2>
{if center_website}
<div class="greyroundbox right"><a href="{center_website}" class="external-link" target='_blank'>Visit the Website</a></div>
{/if}
<p>{shopping_center_description}</p>
<div class="clear"></div>
{/exp:channel:entries}
Code for pulling in any business data
{exp:channel:entries channel="businesses"}
<li class="{switch='first|'}">
<p>
{business_name}
{categories_shopping}<br />
{if phone}
<strong>Phone</strong>: {phone}<br />
{/if}
<strong>Address</strong>: {address_1}<br />
{if address_2}
{address_2}<br />
{/if}
{city}, {state}, {zip}<br />
{if website}
<em>{website}</em>
{/if}
</p>
</li>
{/exp:channel:entries}
Maybe obvious, but have you added dynamic="no" to your other loop?
{exp:channel:entries channel="businesses" dynamic="no"}

nested template rendering in backbone.js

I have a template like
script type: "text/template", id: "list-template", '''
<div class="display">
<div id="list-name"><%= name %></div>
<span class="list-destroy"></span>
</div>
<div>
<ul id="ul-cards">
</ul>
</div>
<div class="edit">
<input class="list-input" type="text" value="<%= name %>" />
<input id="btnEdit" type="button" value="Save" class="primary wide js-add-list" />
<input id="hdnListId" type="hidden" value="<%= listId%>" />
</div>
<form class="add-list-card js-add-list-card clearfix">
<textarea placeholder="Add card" class="new-card"></textarea>
<input type="button" value="Add" class="primary js-add-card">
<a class="app-icon close-icon dark-hover cancel js-cancel-add-card" href="#" id="closeCard"></a>
</form>
'''
in this template i have <ul id="ul-cards"> element in which i want to render another template which display list inside this ul.
this template is :
script type: "text/template", id: "card-template", '''
<div>
<span class="card-name"><%= name %></span>
</div>
'''
is it possible or i have to do it in another way?
please help me if anyone have idea.
thanks in advace.
it is worked but still i have one problem in data display in
<ul id="ul-cards"> there sholud be 2 as per records in my database but it will display only 1 . data fetch properly but display only last data.
There are two ways to do this: the DOM way and the template way.
The DOM way involves adding your views using DOM methods: you have your ListView and your CardView; the ListView invokes individual CardViews that fill in the ListView's element.
The template way requires that you remember this: backbone's views are policy frameworks, not policy templates. Render doesn't have to render into the DOM. You can use render() to return a string, for example. If your event manager is on the ListView object only (possible; I've done this), then you can have ListView invoke "the resulting array of an array of CardView renders" and insert that directly into ListView's template. This is actually faster, as you only require the browser to analyze the entire ListView HTML blob once, when it's inserted into the innerHTML of the parent DOM object.

Resources