I would like to add some PHP in my form created with Contact Form 7, a WordPress plugin.
I've already tried this but it didn't work: Executing PHP Code in Contact Form 7 Textarea.
Every time I insert the function, my website crashes.
I have a variable stored in a $_SESSION. I have put that variable in a hidden input and now I would like to take the value of the hidden input and place it in the contact form.
How can I do this? Thanks!
Screenshot of the website and the hidden input
Screenshot of the back-end of the form
I think this approach can work for you.
Set a url param to the link. Example domain.com/more-info?previous-link=home-page
In your form add this field
[text* previous-link default:get default:post_meta "Previous link"]
You can see more examples in the docs
Related
I am trying to create a multiform with the plugin "contact form 7".
Everything is working well with the form, but I am trying to get to the first form values in the second form.
For example, my first form fields are name and email.
When I go to the second form, the first form values should be auto-filled there.
You can try using Contact Form 7 Dynamic Text Extension that will help you
Hi my question is very simple but I didn't find the answer on the internet, I want to know how I can take the data from a form field on drupal 7 and display it when submited on another form field?
here is an exemple: Let's say I entered my email on the input below and submited.
How can I redirect the page and take the email field datas I entered to display it on this other form ?
Any idea to create this functionality?
Use form submit handler function and redirect to a url where you can render new form and pass your field value in that url. When you render new form get the field value of previous form from the url and use it in your new form field value.
Thanks
I am trying to pre-populate a set of form fields by passing info via parameters in the URL. I have been able to do this with html forms before by simply adding the parameters to the URL, for example ?name=John. The variable I enter usually appears in the form field.
I am finding that this approach is not working on the latest form. I have been able to identify the parameter names but when I add them to the end of the URL they are not populated in to the form.
For example using website.co.uk/admin/usersearch.php?email=test#test.com I would expect the email field to be populated with test#test.com but the page refreshes and the form is still blank.
Is this because it is a .php form? Is there anyway round this? I only have the options to use the URL or javascript.
Thanks
Give your field value as <?php echo $_GET['email'];?>
Like this :
<input type="text" name="email" value="<?php echo $_GET['email'];?>" />
There is no such default procedure for pre-populating form fields built in to any web server. So, I'm not sure how you got it working earlier. Maybe the developer had actually coded it such that the form pre-population occurred.
For the new form, you could do as Prasanth suggested. However, since you require only JavaScript or HTML, refer to this prior question for further assistance: How to retrieve GET parameters from javascript?
Basically, what you'll be doing is getting the value of the field from the url and setting the field's value to it in the form using JavaScript.
I am trying to use Contact Form 7 to redirect the user to a new page that thanks them and offers more info once the form has successfully been filled.
How can I pass the $_POST[] vars through? I couldn't find anything on Google.
Edit:
I am also trying to use the form to pre-populate a PayPal buy it now button.
According to Contact Form 7 documentation you have to set a JavaScript action hook. By using this hook, you can specify a JavaScript code that you wish to run after the form is successfully submitted. You will find the Additional Settings field at the bottom of the contact form management page. Simply insert the following line into it:
on_sent_ok: "your javascript code;"
If you want you can use following code to redirect to a new page with variables but it will send the variables to the $_GET
on_sent_ok: "location = 'http://yourdomain.com?myVar=somevalue';"
You can retrieve the variable as follows
$myVar = $_GET['myVar'];
Read more, also check add_query_arg.
If I have a form with the following 3 fields:
First Name Last Name Date Of Birth
When the user fills in all 3 fields and submits you will get the URL
http: //fakeURL.php?firstName=Fred&lastName=Flintstone&DateOfBirth=2/5/1952
However, if the user only fills in First Name and Date Of Birth you will get
http: //fakeURL.php?firstName=Fred&lastName=&DateOfBirth=2/5/1952 (where lastName has no value)
How do I achieve
http: //fakeURL.php?firstName=Fred&DateOfBirth=2/5/1952 (where lastName and value are removed from the URL)
I don't want to disable the input field upon using onsubmit. Is there a better way than disabled the input field?
Please help...
Just remove the "name" attribute from the input element.
// using jQuery
$('#inputId').removeAttr('name');
// native Javascript
document.getElementById('inputId').removeAttribute('name');
You must either:
Remove or disable the field from the form before submitting it
Don't submit the form, instead redirect to a URL you construct from the form yourself
Make an AJAX request instead of leaving the page
Aside from those options, you can't submit this form via GET without all the inputs becoming part of the URL. That's part of the HTML and HTTP specifications.
if you are working on angular and using (ngModel), Remove the name attribute in the input field and add
[ngModelOptions]="{standalone: true}"
You should use forms with the GET method only when the new page is supposed to be bookmarked and passed around.
Since you are talking about you taking input from the user (and I presume you also store that input in a database or some similar permanent storage), you should be using POST instead.