简体   繁体   中英

Disable contact form input fields after submit

This is my first time asking a question.

I have a website where you log in, and after login, you can submit a form. (Contact form 7).

I want the input fields to disable after the user have submitted a form, so he can only submit that form 1 time (I have 6 forms total).

My first thought was to insert a row in the database with the username and 0 (Not submitted) or 1 (Submitted). If 1, then disable form, or if 0, then you can submit a form.

My problem is that i can't get wordpress to insert anything in the database. I tried this plugin at first: https://wordpress.org/plugins/contact-form-cfdb7/

and it kind of worked, but now the plugin doesn't insert anything in the database anymore. I have no idea why. I haven't changed anything.

When i insert some php / sql code in functions.php, then when i submit the form, it's just loading. Nothing happens.

Just add the below code to your input tag which you want to disable

<?php echo (isset($_POST['submit'])) ? 'disabled' : ""; ?> 
//if submit method is POST else use $_GET for get method

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM