Gert
June 20, 2019, 6:50pm
1
I would like to send text as a PHP variable to a certain uniform form input value from another page. Sending and receiving the variable already works. But how can I transfer it into the “value” of the following input?
<input name="topic" type="topic" value="<?php echo $form->old('topic'); ?>">
The sent variable is also called "topic".
$topic2 = $_GET['topic'];
If I want to pass “$topic2” to $form->old(‘topic’) with
$form->old('topic') = $topic2
that triggers the following error message:
Can’t use method return value in write context
What do I have to do to pass the variable?
Just use $topic2
instead of trying to assign it.
Gert
June 20, 2019, 8:26pm
3
I’ve already tried that, and it works. However, if the page reloads because the user forgot to fill in a required field, the value content disappears.
How do you pass the variable to the page? I think for this purpose you should then store it in the session, so that it is available across pages.
In the second example, we pass the job reference to the form. Both example pass data to the success page.
You haven’t said what you are trying to achieve, maybe if you post more context, helping you will be easier.
Gert
June 22, 2019, 1:03pm
5
Thanks, it worked with the session method.
I did the following:
The variable ‘topic’ is transferred with PHP via URL e.g.
www.example.de/contact?topic=My%20topic
to the page with the Uniform contact form and then loaded into a session variable there:
<?php
$session = $kirby->session();
if(isset($_GET['topic'])) {
$session->set('subject', $_GET['topic']);
} else {
$session->set('subject', '');
}
and in the input:
<input name="topic" type="topic" value="<?php echo $session->get('subject'); ?>">
If now the page reloads when submitting because a required field has not been filled in, the content of ‘value’ is preserved.