ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Safecracker -- required

October 17, 2011 8:58am

Subscribe [2]
  • #1 / Oct 17, 2011 8:58am

    techjob

    22 posts

    Does anyone have a working example of safecracker using required fields.

    thanks
    pete

  • #2 / Oct 17, 2011 12:54pm

    Mark Bowen

    12637 posts

    Hi Pete,

    Have you tried anything yet here in your template code? Do you have any code you can show us that you are currently using?

    It may not help for other people to show their code as their field names and setup won’t be the same as what you are trying to do here so would be best if we can get you set up with your own code instead.

    Therefore if you can show us what you have attempted so far and then we can go from there.

    As a slight aside have you seen the rules://my_field_name=”“ parameter in the documentation?

    Thanks,

    Mark

  • #3 / Oct 18, 2011 8:30am

    techjob

    22 posts

    Yeah I’ve tried using that code
    rules:description =“required”
    to no effect.
    I’ve tried adding the code {if required}* {/if} as a test but still nothing.

    That’s why i’m looking for a simple working example that i can take apart and compare to my own.

    thanks
    Pete

  • #4 / Oct 18, 2011 10:20am

    Mark Bowen

    12637 posts

    Hi Pete,

    As an exceptionally simple test here is some code for you :

    {exp:safecracker channel="test" return="safecracker/thanks" rules:test_body="required"}
    Title :   <input name="title" type="text"><br >
    Body :   <input name="test_body" type="text"><br >
    Submit :   <input type="submit" value="Submit">
    {/exp:safecracker}

    You will want to change channel=“test” in the code above to your Channels short name and also change test_body in both the Safecracker rules:test_body=“required” parameter and also for the name of the field in the form but basically if you have it all setup like the above if you typed in a Title but not anything in the test_body field then when you press the Submit button you should get a page with a message on it telling you that the field is required. There will then be a link on that page for you to go back to the form and fill it in before trying to submit again.

    Hopefully that is what you’re looking for here?

    Thanks,

    Mark

     

  • #5 / Oct 20, 2011 2:01pm

    techjob

    22 posts

    Hi Mark,
    Still not doing anything, even if i fill out all it desn’t submit anything.
    here’s what I have:

    <div class="grid_12">
     {exp:channel:entries channel="hosts" orderby="conference_date" sort="desc" limit="1" disable="member_data|trackbacks"}
     <? $currHost = {entry_id} ?>
     {/exp:channel:entries}
     {exp:safecracker channel="ztemp" return="contact/thanks" rules:description_test="required" logged_out_member_id="3"}
     Description{if required} *{/if} :  <input name="description_test" type="text"><br >
     Relationship :  <input name="relationship_test" type="text" value="<?=$currHost ?>"><br >
     Submit : <input type="submit" value="Submit"><br >
     {/exp:safecracker} 
    </div>

    in the source of the page it looks like this:

    <div class="grid_12">
    <form id="publishForm" method="post" action="http://my.site.com/ztemp"  enctype="multipart/form-data" >
    <div class='hiddenFields'>
    <input type="hidden" name="ACT" value="1" />
    <input type="hidden" name="RET" value="http://my.site.com/ztemp" />
    <input type="hidden" name="URI" value="ztemp" />
    <input type="hidden" name="XID" value="8a56f86c05054835ada555e8c68b7eab260197f3" />
    <input type="hidden" name="return_url" value="contact/thanks" />
    <input type="hidden" name="author_id" value="3" />
    <input type="hidden" name="channel_id" value="10" />
    <input type="hidden" name="entry_id" value="0" />
    <input type="hidden" name="site_id" value="1" />
    <input type="hidden" name="return" value="contact/thanks" />
    <input type="hidden" name="allow_comments" value="n" />
    <input type="hidden" name="rules[description_test]" value="sifshgtlVpAph/tZyr31tW+f/Qw5L2bLjCjkQeiPegk=" />
    <input type="hidden" name="logged_out_member_id" value="QfgshCtmQkPGCyqVTtVfYKt3iaoh9u+EEN49TAn1O4U=" />
    </div>
    Description :  <input name="description_test" type="text"><br >
    Relationship :  <input name="relationship_test" type="text" value="335"><br >
    Submit : <input type="submit" value="Submit"><br >
    </form>

    am i missing something?

    thanks again for all your help.
    Pete

  • #6 / Oct 21, 2011 11:26am

    Mark Bowen

    12637 posts

    Hi Pete,

    If you use the code that I supplied above with the Channel Name changed to reflect your channel does it not work?

    {exp:safecracker channel="hosts" return="safecracker/thanks" rules:test_body="required"}
    Title :   <input name="title" type="text"><br >
    Description Test :   <input name="description_test" type="text"><br >
    Submit :   <input type="submit" value="Submit">
    {/exp:safecracker}

    Could you try the code above in a template with nothing else in it please and see if that works for you.

    From looking at your code above you are trying to set the value of the relationship_test field using a Channel Entries tag above it and some PHP.

    This is not going to work in the way you have it as you will be running into parsing order issues here.

    To that end could you try the code I’ve posted above just so that we can make sure that Safecracker can indeed post without any problems first and then we can look at exactly what it is that you are trying to achieve here as there may well be a better way of going about all of this that we can help with.

    Thanks,

    Mark

     

  • #7 / Oct 24, 2011 8:38am

    techjob

    22 posts

    Hi Mark,
    i tried with your code and still nothing, when i submit the form the page just reloads the form blank.

    here’s the source of your code:

    <form id="publishForm" method="post" action="http://acrao.peteeaston.com/ztemp"  enctype="multipart/form-data" >
    <div class='hiddenFields'>
    <input type="hidden" name="ACT" value="1" />
    <input type="hidden" name="RET" value="http://acrao.peteeaston.com/ztemp" />
    <input type="hidden" name="URI" value="ztemp" />
    <input type="hidden" name="XID" value="" />
    <input type="hidden" name="return_url" value="safecracker/thanks" />
    <input type="hidden" name="author_id" value="1" />
    <input type="hidden" name="channel_id" value="10" />
    <input type="hidden" name="entry_id" value="0" />
    <input type="hidden" name="site_id" value="1" />
    <input type="hidden" name="return" value="safecracker/thanks" />
    <input type="hidden" name="allow_comments" value="n" />
    <input type="hidden" name="rules[test_body]" value="ft/NL44fsi7P7sljLMODeMeXChp8CD4w0GWMkGlCZuM=" />
    </div>
    Title :   <input name="title" type="text"><br >
    Description Test :   <input name="description_test" type="text"><br >
    Submit :   <input type="submit" value="Submit">
    </form>[removed]//lots of java after this

    i’ve attached a screen shot of the safecracker setup:

  • #8 / Oct 25, 2011 10:53am

    Mark Bowen

    12637 posts

    Hi Pete,

    That is correct that the form will come back again blank as in the return=”“ parameter I just set it to be the form again so that you can submit an entry and then very quickly come back to the form again and submit another.

    Could you check in your Control Panel to see if the entry did submit to the database though please.

    Thanks,

    Mark

  • #9 / Oct 26, 2011 3:12pm

    techjob

    22 posts

    HI Mark,
    I did check (several times) and nothing.
    Also the code you sent does have a return url

    {exp:safecracker channel="hosts" return="safecracker/thanks" rules:test_body="required"}

    i’m not sure what to do next

    Pete

  • #10 / Oct 28, 2011 5:17pm

    Kevin Smith

    4784 posts

    Hi Pete,

    Is this on an server that we might be able to access? I think it’s going to help us figure things out quicker if we have a first-hand look at this. Be on the lookout for an email from me.

  • #11 / Oct 29, 2011 3:51am

    Mark Bowen

    12637 posts

    Hi Pete,

    Okay a few things are happening here.

    First up I’ve created a new template in your ztemp template group called test which shows the correct code :

    {exp:safecracker
     channel="ztemp"
     rules:description_test="required" 
     return="/ztemp/test/thanks"}
    Title :   <input name="title" type="text"><br >
    URL_Title :   <input name="url_title" type="text"><br >
    Description Test :   <input name="description_test" type="text"><br >
    Submit :   <input type="submit" value="Submit">
    {/exp:safecracker}

    As you can see from the above I’ve changed the return=”“ parameter to reflect your template_group and template_name of your Safecracker form. Sorry I should have mentioned that this needed to be your template_group and template_name. I’d just placed what I did in my code as an example.

    Next up you had also still got :

    rules:test_body=“required”

    in your form yet the short name of test_body should have been changed to :

    rules:description_test="required"

    to reflect the name of the field in your form.

    The last thing which was causing most of the problems though was the use of the NSM .htaccess Generator extension.

    I went in and renamed your .htaccess file to stop it from affecting the site whilst working on it and also disabled the extension.

    I then replaced index.php back into Admin > General Configuration > Name of your site’s index page and loaded up the ztemp/test template.

    Everything now works fine with the form, entries are added to the ztemp Channel and if you don’t fill in the description_test field you will see an error message come up.

    I’ve now renamed your .htaccess file to ORIGINAL_htaccess and added in the method for the removal of index.php from our documentation shown here.

    I’ve now taken out the index.php from your Admin > General Configuration setting and all is now working fine without the index.php in the URLs.

    If you do need your site to use the NSM .htaccess Generator extension then you will need to contact the author of that add-on as it was definitely the main issue of your form not working here. It would have probably also caused quite a few other problems in other areas of your site too.

    I’ve left it disabled for now so that you can see your site working. If you do want to re-enable it then that will be up to you but we can’t support 3rd party add-ons here and as that was causing the issues here I really would advise you to go with the removal method as outlined in our documentation above.

    That is the only method we can support and it is working fine on your server so hopefully that should all help out a bit.

    You will also notice in your template that I’ve placed the code :

    {if segment_3 == "thanks"}
    Thanks for filling out our form!
    
    {/if}

    This is a really simple conditional that checks for the existence of thanks in the third segment of the URL. As the form is currently set to go back to the form again after it is filled out (just a quick way of doing things if you wanted people to be able to fill out the form again quickly) this is what the /thanks is for in the return=”“ parameter.

    You don’t have to have that there but I just thought I’d show why I’d made the return=”“ parameter what I had.

    Hope that helps a bit.

    Thanks,

    Mark

     

  • #12 / Oct 29, 2011 8:14am

    techjob

    22 posts

    Holy Crap you guys are amazing!
    I’ll go through it all later this afternoon. maybe a note should be added to the safecracker page regarding the incompatibility.
    one last question: do i have to set up a rule for each field or can i pipe the in one? ie rules:name|name=“required”

    thanks again
    Pete

  • #13 / Oct 29, 2011 9:32am

    Mark Bowen

    12637 posts

    Hi Pete,

    Regarding adding a note of incompatibility I don’t really think that would be feasible because otherwise we would need to add notes regarding all incompatibilities with 3rd party add-ons which could take a while 😉

    As not everyone will use those add-ons and 3rd party add-ons are not something we support anyway it’s definitely better this way.

    As for your question about multiple fields I believe you need to add them in as separate rules so something like :

    rules:description_test="required"
    rules:another_field_name="required"

    Does that help?

    Thanks,

    Mark

     

  • #14 / Nov 01, 2011 10:44am

    Kevin Smith

    4784 posts

    Hi Pete,

    Just checking in to make sure Mark was able to clear up your remaining questions. Is there anything else I can help you with?

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases