How to handle more steps form? - php

I'm creating plugin in Wordpress with more steps form, and I would like to take some advice from you.
I've one function (using shortcode) with first form, after submit, I'd like to go on next step, but I don't know which solution is the best
My function:
function task_shortcode(){ ?>
<form id="form" action="" method="post">
<h3>Add new task</h3>
<div class="task-title">
<label>Title</label>
<input type="text" id="text" name="text">
</div>
<div class="task-description">
<label>Description</label>
<textarea id="desc" name="desc"></textarea>
</div>
<div class="task-new">
<input type="submit" id="create-task" name="create_new_task" value="Create new task">
</div>
</form>
<?php
}
add_shortcode('task_site','task_shortcode');
After that I want to go to another form and I dont know how to handle it. Using classic php action on submit button, or is there another solution?
I've found this, but I don't know if I can use it, because I want it to use on frontend.
https://www.sitepoint.com/handling-post-requests-the-wordpress-way/
Thanks for every advice

Related

How to run php on a button click

So I have been browsing trough a lot of threads, and the only suitable solution for my situation I found was this:
PHP:
<?php
if(isset($_POST["submit"])) {
my php code goes here
}
?>
HTML:
<form id="usp-form-23" class="usp-form" method="post" enctype="multipart/form-data" action="" data-validate="parsley" data-persist="garlic" novalidate>
<input name="usp-title" type="text" value="" data-required="true" required="required" maxlength="99999" placeholder="Answer" class="usp-input usp-input-title" />
<input name="submit" id="submit" type="submit" class="usp-submit usp-submit-default" value="Send Message" />
</form>
But it doesn't work.
Maybe I'm missing something?
Need help.
P.S. I can't use an external php file. Only php code inside the same file, because of the variables I need to grab from the post.
I also can't use $_GET, because if a person refreshes the page, my php will be repeated, which I don't want. I only need to run my php once.

Viewing a Text-Box after a Button Click PHP

I know this question has been asked before multiple times on StackOverFlow. I have implemented a method to generate a text box for Button click event. But my issue is text box is already visible before performing the clicking. I need to view the text-box when someone clicks the button. I'll put my coding down below.
Coding for the text-field
<div id="inputField" style="display:none;">
<input type="text" id="textInput" value="" />
</div>
Coding for the Button click event
Click me
Just to make more sense, I'll attach a screenshot of my coding and the graphical view of the form.
I'm kindly requesting from everyone not to mark this question as duplicate. I did my best to fix this issue by my own. Though I'm a newbie to this field I couldn't make it up. Any help would be really appreciated. Thank you!
Try the html with:
<form method="post" action="?btnpressed=1">
Click me
</form>
And in the php:
<?php
if(isset($_GET['btnpressed']{
if(isset($_POST['btn']{ ?>
<div id="inputField" style="display:none;">
<input type="text" id="textInput" value="" />
</div>
<?php
}
}
?>
I hope this helps...

Multiple forms using the action variable?

I have a page that has multiple php forms that send me different informations depending on the user and the form. How do I make php differentiat these? I saw something about the actions and I thought maybe it was like having a separate file, but when I created a "questions.php" and copied and pasted my php code into that and then added "action="questions.php"" to the tag, and ran it just as I had before it didn't work. So what is the correct way to do this?
My code is extremely long and filled with words which is why it would be nice to have separate files for it depending on the form instead of all in the top of my main page.
You could build one page as a standard page. in this page you could include the different forms. See the example below:
<!-- These are just example names -->
<div class="form-1">
<?php include "forms/form-1.php"; ?>
</div>
<div class="form-2">
<?php include "forms/form-2.php"; ?>
</div>
<div class="form-1">
<?php include "forms/form-3.php"; ?>
</div>
If you would like to save data that a user puts in a form in lets say a database you should use the <form method="post"> by adding an action to it. You're asking the form to send the user to another page when the submit button is clicked. an example of a form down below.
<form class="form-1" method="post" action="second_page.php">
<label>Name:
<input type="text" class="input" name="name">
</label>
<label>Email:
<input type="email" class="input" name="email">
</label>
<button type="submit">Send!</button>
</form>
Hope this helps!
I just added a / before the questions.php. apparently it had to do with file path? I don't understand it but it works now.
<form action="questions.php" method="post">
<!-- text boxes to get user inputs-->
<button type="submit" value="submit_btn">click here to go to page in action tag
</button>
</form>
If questions.php file is in same folder action="questions.php" is enough. If its inside 'x' folder, correct path should be given as action="x/questions.php"

User input not showing in search form

I have a free form search that I moved from my main content to my header. Once I moved the form into the header the text inside of it stopped showing. The placeholder works but when you begin typing it is completely blank. The search and the functionality work perfectly, I just cannot see what I am typing. Any ideas?
<form class="search" action="/all-results/" method="get">
<fieldset>
<span class="text"><input name="searchProducts" value="All" type="hidden">
<input type="hidden" name="search_selection" value="all">
<input name="byString" id="s" type="text" value="" placeholder="<?php echo __('Search','Avada'); ?>" /></span>
</fieldset>
<form name="input" action="/all-results/" method="get">
<input type="submit" id="search_button" value="Search">
</form>
</form>
Your HTML is invalid. You can not nest a <form> element inside another <form>. Messing up forms and tables are two of the best ways to produces peculiar browser behaviour, so my guess is that this is your problem.
If you correct your HTML (validate it!) and the problem persists, then post a minimal HTML page with CSS so that there is something for us to debug.

Email contact form without PHP

I'd like to use a contact form for a website I'm creating, but PHP is not an option since the client doesn't wish to use it. Is there a clever way to work around this somehow, by sending email parameters (which is non-standard) perhaps, or by using an external contact form? Are there any good ones that don't use advertising and are easily modified to a different language for example?
Thank you.
Check out formspree.
https://github.com/asm-products/formspree
For action you simply put:
<form action="http://formspree.io/you#email.com" method="post">
<input type="text" name="name">
<input type="email" name="_replyto">
<input type="submit" value="Send">
After verifying your email after the first send this will email you the contents of the form. One thing to keep in mind is that this will take the input names. If you do not include input names it won't send you that form field.
There are hundreds of embeddable (most likely iframe-based) solutions for contact forms, which would enable you to get around using a server-side language like PHP. Just a quick google search will give you some.
Alternatively, you could make a form in HTML, and have a submit button which is actually a mailto: link, and you modify the parameters of that mailto as your form inputs change.
The only downside of this is that it's not as convenient for the user, as it then opens up their email client and they have to actually send it.
Personally, I would try and persuade the client, but if that isn't possible, then those are your options.
Check out www.enformed.io.
Has a couple of interesting options that formspree does not have( Like redirect out of the box, and a html email editor).
I used Formspree but formspree doesn't allow ajax unless you have Gold Version. It doesn't work on the basic so I am planning on making an account on enformed.io. I still haven't used it but I have heard that t is very good. You can also use alerts fro success and error messages.
<form style="margin-left: 6%;" class="email" action="https://www.enformed.io/YOUR_TOKEN" method="post">
<p>Name:</p>
<input type="text" name="first_name" />
<div id="margin" style="height: 0.5%;"></div>
<p>E-mail:</p>
<div id="margin" style="height: 0.5%;"></div>
<input type="text" name="email" />
<div id="margin" style="height: 0.5%;"></div>
<p>Subject:</p>
<div id="margin" style="height: 0.5%;"></div>
<input type="text" name="subject" />
<div id="margin" style="height: 0.5%;"></div>
<p>Message:</p>
<div id="margin" style="height: 0.5%;"></div>
<textarea name="message"></textarea>
<div id="margin" style="height: 0.5%;"></div>
<button type="submit" class="btn btn-default">Submit Form</button>
</form>
Would something as simple as a mailto form work?

Categories