Jump to content
photoman355

Strange 404 after adding field value?

Recommended Posts

I've just come across a really strange problem where processwire is throwing a 404 error after I enter a value into one of my fields.  I'm sure this is probably down to my code.  

I have a set of fields that when a value is entered some output is echoed to my template.  Every field works as expected except the last field which throws the 404 after entering a value and saving the page.  

Here's the code.

 <?php 
$settings = $pages->get("/site-settings/");

if ($settings->social_facebook) echo "<li><a class='icon-small small-icon-facebook' href='{$settings->social_facebook}' target='_blank'></a></li>";
if ($settings->social_twitter) echo "<li><a class='icon-small small-icon-twitter' href='{$settings->social_twitter}' target='_blank'></a></li>";
if ($settings->social_linkedin) echo "<li><a class='icon-small small-icon-linkedin' href='{$settings->social_linkedin}' target='_blank'></a></li>";
if ($settings->social_youtube) echo "<li><a class='icon-small small-icon-youtube' href='{$settings->social_youtube}' target='_blank'></a></li>";
if ($settings->social_picasa) echo "<li><a class='icon-small small-icon-picasa' href='{$settings->social_picasa}' target='_blank'></a></li>";
if ($settings->social_upon) echo "<li><a class='icon-small small-icon-stumble' href='{$settings->social_upon}' target='_blank'></a></li>";
?>

I'm guessing there's a better way to write this but not quite sure why it's throwing an error.  I've tried deleting and recreating the last field with a different name but it still throws the same error.

Can anyone help?

Share this post


Link to post
Share on other sites

PW fields have nothing to do with 404. Its a page not found error page that always comes from when entering a url that does not exist or is not viewable.

Share this post


Link to post
Share on other sites

Thanks Soma.  I don't understand what's causing the 404 as all I'm doing is saving a field value on an admin page.  The field isn't redirecting any urls it's only a textfield to provide output for the template.  

Is there a procedure to troubleshoot?

Share this post


Link to post
Share on other sites

Ah when saving the page?

Of course if you provide more infos so we could reproduce we may be able to know whats going on.

And what does the template code have to do with it?

Share this post


Link to post
Share on other sites

so in other words you have a text field called social_upon and when you enter data into that field and save, you get a 404 error.

You should post the URL that PW is redirecting to on save;

try disabling some modules also, to account for possible conflicts; also post screenshot ?

Share this post


Link to post
Share on other sites

@Soma I only thought the template code was at fault because everything worked up until I added the new code.

@Macrura That's correct, entering data into any of the other text fields and saving works fine but for some strange reason entering data into social_upon and saving throws the 404.  This happens even if I empty one of the other fields and fill the social_upon field.  I've tried creating a new field with a different name but no joy.

For URL's the page is at mydomain.com/login/page/edit/?id=1011.  When I hit save I get the 404 error message "The page you were looking for is not found.Please use our search engine or navigation above to find the page.".  The URL on that page is exactly the same.

As I'm developing I still have the default site template and it's relevant files installed (my home.php has been modified).  My new template calls a different header, footer and template files. It's redirecting to the default install template page possibly because it's assigned as the default for 404's? 

Modules wise I don't have many installed outside the default ones just, Fieldtype Crop Image, CK Editor, HTML Purifier, Modules Manager and Process Page Delete.

Is there anything I should try?  

Share this post


Link to post
Share on other sites

mydomain.com/login/page/edit/?id=1011 ... is /login/ you PW admin/installation?

It's just I'm not sure where template files would be involved in backend editing? This is not possible I think.

What fields are they? What data do you enter extactly? The only scenarion that comes to mind is that you enter some data in that last field that is suspicious and maybe some security setting on server does not allow for posting those through a form and you get a 404... But maybe not.

Ok seeing the modules list, try deinstalling some of those like Process Page Dele, Modules Manager, HTML Purifier?

Share this post


Link to post
Share on other sites

yes it sounds like you're getting booted from the admin, or there is some error going on, perhaps with duplicates in the database...

one thing i would try is repairing the database, you can login to your phpMyAdmin and run the database repair

Share this post


Link to post
Share on other sites

@soma Yes I changed the default login from /processwire to /login mainly to make it more memorable for clients.

For setup I have 6 textfields (all use the default settings) and the last textfield is what I'm having trouble with.  I did get a little further on today.  Tried repairing the database as Macrura suggested which all checked out fine.  I then returned to the admin and entered some different data with some success.  

What I was entering before was a URL in the format "http://www.google.com" and saving the page throws an error.  I changed the entry to "www.google.com" and the page saves fine, no 404.  Very strange.  Next I changed the last field from a textfield to a URL.  Now when I go back to the admin page in question the URL field re-writes the last entry from "www.google.com" to  "http://www.google.com".  When I hit save I get the 404 again.

It's clearly something to do with the "http://" part of the entry.  Soma you suggested this could be server security. Can you explain a bit more?

Just something else to add.  I'm currently testing out the multisite install and this particular database is a clone from another of my PW sites.  I just exported the database from a master site and imported into a new database via phpmyadmin.  I don't know if this is significant or not?  

Share this post


Link to post
Share on other sites
It's clearly something to do with the "http://" part of the entry.

I'm assuming the 404 you are getting is an Apache one rather than a ProcessWire one. You are seeing mod_security in action. When mod_security gets in the way of legitimate content management, then it's configured in an overly agressive manner. I would ask your host to loosen things up a bit, or if they can't, have them disable mod_security for your account. 

  • Like 1

Share this post


Link to post
Share on other sites

Aha that would make sense as my hosting company has been pretty poor of late.  Many thanks for the info Ryan.  How would I tell if this is definitely an Apache 404 vs a Processwire one?  

I've been in touch and asked them to lighten up the security rules and they said they've changed them but I'm still having issues.  Before I go back to them I thought I'd try to disable mod_security using htaccess.  I added "SecFilterEngine Off" to htaccess but after adding it locks me out of my PW site.  I don't have much experience on the server side so I've probably tried to change completely the wrong setting.

Is there a correct way to manually disable mod_security so I can check this is definitely the problem?  I have access to cpanel if that helps.

Share this post


Link to post
Share on other sites
 How would I tell if this is definitely an Apache 404 vs a Processwire one?  

The ProcessWire 404 will look like your site. The Apache 404 will look like plain text. Though I actually think this is mod_security either way. 

Is there a correct way to manually disable mod_security so I can check this is definitely the problem?

I think this is something that only your host can answer. Though if someone else knows better, hopefully they will reply. 

Share this post


Link to post
Share on other sites

Many thanks Ryan.  The 404 the page in question is a site-settings page that has no associated template file.  Would a processwire 404 from this page not be output as plain text anyway as there's no header and footer or would a 404 still show the admin header and footer?

I'm sure you're right in saying it's mod_security anyway.  My hosting company are useless :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By EyeDentify
      Hello Dear PW Gurus.

      Hope you fair well in these Corona Crisis times.

      Anyhow, i have a problem with a Cryptic error message that shows up when i am trying to Delete images out of a Images field.
      The Error message does say a little but it does not make sense to me why i can´t delete the images because of it.

      Is it some permission issue perhaps?

      I will attach screenshots of it and what i did prior to it.
      I am from sweden so ignore the funny words here and there.

      Hope you all can send me on the right track.
      i am running PW 3.0.139 on this install.

      Step1:

      Step 2: Select the images with the trashcan symbol

       
      Step 3: Cryptic Error message

      I am scratching my head on this one, have not seen this before.

      Thankfull for all help.
      /EyeDentify
    • By DV-JF
      Hey all, hope you're feeling well these days!
      Short question: Under "Setup > Templates" it's possible to sort the templates by last modified. Is this possible for fields view to?
      Long explanation:
      Currently I am in the process of programming a reusable template and often have to copy several fields & templates from different PW installations into my "master version".
      Therefore it would be good to see already in the field list when the last modification has taken place.
      Stay healthy & don't forget to wash you hands - many greets!
    • By ngrmm
      I have a page with a table. Each table row has a page-reference field and a checkbox.
      The Page sends emails to all users (page-refrence->email-field) and change the value of the checkbox in a row to 1.
      It works with this:
      <?php // event ID fron url query $eventID = $input->get('eventID','int'); // get event-page $event = $pages->get($eventID); // config $fromEmail = $event->event_mail_from; $fromName = $event->event_mail_from_name; $emailSubject = $event->event_subject; // email html body ob_start(); include('./_inc/emailbody.inc'); $emailBody = ob_get_clean(); // make event-page editable $event->of(false); // loop through table and send out emails foreach($event->event_clients_list as $event_table_row) { // get client page $clientPage = $event_table_row->client_name; // get client email $clientEmail = $clientPage->email; // if client isn't invited yet (checkbox not checked) if($event_table_row->client_invited == '') { // send email $m = new WireMail(); $m->to($clientEmail); $m->from($fromEmail, $fromName); $m->subject($emailSubject); $m->bodyHTML($emailBody); $m->send(); // mark client as invited $event_table_row->client_invited = 1; $event->save('event_clients_list'); } } ?> But i have to use a variable in my emailbody.inc which i'm able to get in the table-loop.
      So i do the including of the body inside my loop. But this doesn't work anymore. Page sends out the emails but is unable to change the value of the checkbox.
      I get no errors!
      I'm using ProTable
      <?php // event ID fron url query $eventID = $input->get('eventID','int'); // get event-page $event = $pages->get($eventID); // config $fromEmail = $event->event_mail_from; $fromName = $event->event_mail_from_name; $emailSubject = $event->event_subject; // loop through table and send out emails foreach($event->event_clients_list as $event_table_row) { // get client page $clientPage = $event_table_row->client_name; // get client email $clientEmail = $clientPage->email; // email html body ob_start(); include('./_inc/emailbody.inc'); $emailBody = ob_get_clean(); // make event-page editable $event->of(false); // if client isn't invited yet (checkbox not checked) if($event_table_row->client_invited == '') { // send email $m = new WireMail(); $m->to($clientEmail); $m->from($fromEmail, $fromName); $m->subject($emailSubject); $m->bodyHTML($emailBody); $m->send(); // mark client as invited $event_table_row->client_invited = 1; $event->save('event_clients_list'); } } ?>  
    • By Robin S
      This module is inspired by and similar to the Template Stubs module. The author of that module has not been active in the PW community for several years now and parts of the code for that module didn't make sense to me, so I decided to create my own module. Auto Template Stubs has only been tested with PhpStorm because that is the IDE that I use.
      Auto Template Stubs
      Automatically creates stub files for templates when fields or fieldgroups are saved.
      Stub files are useful if you are using an IDE (e.g. PhpStorm) that provides code assistance - the stub files let the IDE know what fields exist in each template and what data type each field returns. Depending on your IDE's features you get benefits such as code completion for field names as you type, type inference, inspection, documentation, etc.
      Installation
      Install the Auto Template Stubs module.
      Configuration
      You can change the class name prefix setting in the module config if you like. It's good to use a class name prefix because it reduces the chance that the class name will clash with an existing class name.
      The directory path used to store the stub files is configurable.
      There is a checkbox to manually trigger the regeneration of all stub files if needed.
      Usage
      Add a line near the top of each of your template files to tell your IDE what stub class name to associate with the $page variable within the template file. For example, with the default class name prefix you would add the following line at the top of the home.php template file:
      /** @var tpl_home $page */ Now enjoy code completion, etc, in your IDE.

      Adding data types for non-core Fieldtype modules
      The module includes the data types returned by all the core Fieldtype modules. If you want to add data types returned by one or more non-core Fieldtype modules then you can hook the AutoTemplateStubs::getReturnTypes() method. For example, in /site/ready.php:
      // Add data types for some non-core Fieldtype modules $wire->addHookAfter('AutoTemplateStubs::getReturnTypes', function(HookEvent $event) { $extra_types = [ 'FieldtypeDecimal' => 'string', 'FieldtypeLeafletMapMarker' => 'LeafletMapMarker', 'FieldtypeRepeaterMatrix' => 'RepeaterMatrixPageArray', 'FieldtypeTable' => 'TableRows', ]; $event->return = $event->return + $extra_types; }); Credits
      Inspired by and much credit to the Template Stubs module by mindplay.dk.
       
      https://github.com/Toutouwai/AutoTemplateStubs
      https://modules.processwire.com/modules/auto-template-stubs/
    • By DV-JF
      Hi, 
      I'm using this kind of setup (https://processwire.com/blog/posts/language-access-control-and-more-special-permissions/#language-page-edit-permissions) in order to control the page edit permissions. Now I'm wondering if it's possible to hide the "none-ediable" language-tabs instead of striking them through.

      Many greets...
       
×
×
  • Create New...