• I’m using Contact Form 7 but the author doesn’t respond to this particular query.

    They’re changing the on_sent_ok feature from being per form, to the functions.php file.

    Now I’m either grossly misunderstanding, or in future that means we have magic numbers in a functions.php shared across different sites and hopefully no ids clash.

    I assume that’s what they want to do, so can someone explain why it’s great to split a form definition between a php file and the db?

    Or is there another plugin that works a bit more with encapsulation?

    The page I need help with: [log in to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
  • If you used on_sent_ok then it would be associated with the form ID in the database anyway, so I don’t see what the problem is referring to an ID in your code.

    I’m not clear why a functions.php that used this featured would be shared across sites either? That PHP can be added into a simple plugin file that you’d only use for one site if you wanted.

    Thread Starter funsail

    (@funsail)

    I don’t see what the problem is referring to an ID in your code.

    There’s a difference with an “associated id” and typing magic numbers out in code. I’m sure anyone who has passed programming 101 knows not to use magic numbers.

    Technically your username is an “associated id”, yet I can type @jakept rather than #32984729384. Surely you see there’s a difference? I reference a file as path/file.php rather than inode #9238579487543.

    I’m not clear why a functions.php that used this featured would be shared across sites either?

    That’s how themes work. You make a child theme, you use the theme across sites that need the same features. Yeah you can do workarounds. It doesn’t make it right. And are you proposing that a contact form plugin requires you to write another plugin to get it to work semi-maintainably? Plugins are not only aimed at developers. Normal people should be able to use them.

    OOP has been important to maintainably since forever. If I used on_sent_ok it’s saved WITH the form in the database. If I delete the form the on_sent_ok is deleted. It’s maintainable. It’s sane.

    If I delete a form without telling you which it was, how will you delete the “if” statement from the php? Will you search every id in the php to see if there’s a form on it? Will you know whether each id appears only once, or more? It’s insane.

    Are you seriously telling me you can’t see a difference in approaches? People wrote amazing code in assembly, but I sure don’t want to go there.

    If you’re building functionality that you’re going to distribute across multiple sites that interacts with the wpcf7mailsent event of forms that are picked by the users then I’m sure you – expert programmer that you clearly are – would be perfectly aware that any ID in code could be substituted with a variable, and that you could add a field or option somewhere in WordPress that would be used for selecting that ID to associate it with the form.

    If you were distributing the functionality across multiple sites, then you wouldn’t be using on_sent_ok anyway because that’s just storing it with the form in the database of one particular site. Besides, storing code in the database to execute when a form is submitted is hardly acceptable programming 101 either. Hence its removal.

    If you want the developer of Contact Form 7 to do this for you, then take that up with him. Otherwise, there’s nothing about the new solution that mandates magic numbers, you just need to do more work.

    Thread Starter funsail

    (@funsail)

    Hi Jacob.

    Thanks for your time.

    If you’re building functionality that you’re going to distribute across multiple sites that interacts with the wpcf7mailsent event of forms that are picked by the users then I’m sure you – expert programmer that you clearly are – would be perfectly aware that any ID in code could be substituted with a variable, and that you could add a field or option somewhere in WordPress that would be used for selecting that ID to associate it with the form.

    I’m not a programmer, that is why I don’t want to deal with unmaintainable code. That’s why I’m asking you why it’s a good idea to have a php file that’s tied to a particular database. I cannot imagine why it is better than having all functionality related to a form with the form.

    Frankly trying to understand that doco gives me headaches. It seems to be going from a user plugin to a dev plugin.

    I don’t have the first clue about adding a variable and all that, but if I were to add a field or option somewhere in WordPress it would be on the plugin page, when I had a form selected. Which is the old functionality. Which has something wrong with it so that we should do it in a php instead.

    If you were distributing the functionality across multiple sites, then you wouldn’t be using on_sent_ok anyway because that’s just storing it with the form in the database of one particular site.

    I’m not. I have different forms on different sites, that do different things and redirect or do different analytics things. I’m saying I use the same theme across multiple sites, hence I don’t want to put site specific code in a theme file.

    Besides, storing code in the database to execute when a form is submitted is hardly acceptable programming 101 either. Hence its removal.

    Everything in WordPress is executable and in the db isn’t it? When I have a grid or slider that you can click that is code. Page builders are full of code. HTML in itself is code. I really don’t understand it at all.

    If there’s a choice of the cleanest implementation possible by an author, or not having a functionality or having random programming 101 people like me hacking things together, surely the former is better?

    Right now you’ve shown me the best outcome is to do more work to make some field that shows on a different page to the contact plugin that links some id to some variable to a php file. It doesn’t sound ‘better’.

    Moderator Jan Dembowski

    (@jdembowski)

    Forum Moderator and Brute Squad

    Don’t use Developing with WordPress for plugin support and don’t create duplicate topics.

    As you know, the correct forum for that plugin is here.

    https://wordpress.org/support/plugin/contact-form-7/

    Please continue to use that forum for plugin specific topics.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Using a contact form’ is closed to new replies.