John Davidson

php - WordPress: Input Box displays Input data on the next page

0 comments
Message:


How to:



  • Add an Input Text Box on my homepage

  • The website visitor fills the box, submits

  • He is redirected to a page on which the text he wrote in the box is displayed on screen



My Answer:
To achieve this functionality in WordPress, you can follow these steps:

1. Create a new page template in your WordPress theme where you want to display the input box and the submitted text.

2. In the page template file, add the following code to create an input text box:

html







3. Add the following code to your theme's functions.php file to handle the form submission and display the input text on the next page:

php
function display_user_input() {
if ( isset( $_POST['user_input'] ) ) {
$user_input = sanitize_text_field( $_POST['user_input'] );
echo '

Your input: ' . $user_input . '

';
}
}
add_action( 'admin_post_display_user_input', 'display_user_input' );


4. Create a new page in WordPress and assign the custom page template you created earlier to it.

5. When a visitor fills the input box and submits the form, they will be redirected to the same page and the text they entered will be displayed on the screen.

By following these steps, you can easily add an input text box on your homepage in WordPress and display the input data on the next page.

Rate this post

3 of 5 based on 4653 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us