I have a form where the users submit a text. Here is the code:
$form['reason'] = array(
'#type' => 'textfield',
'#title' => '',
'#size' => '200',
'#attributes' =>array('placeholder' => t('*Reason')),
'#prefix' => '<div>'
);
$form['newsletter_unsubscribe_submit'] = array(
'#type' => 'submit',
'#value' => 'Submit',
'#attributes'=> array(
'class' => ['btn', 'btn-primary']
),
'#ajax' => array(
'callback' => 'newsletter_unsubscribe_quiz_submit_driven_callback_share',
'method' => 'replace',
'effect' => 'fade',
),
'#prefix' => '<div class="regular newsletter_unsubscribe_button">',
'#suffix' => '</div></div>');
return $form;
I managed to get the input of the user on a variable using $_values = $form_state['values'];
Also, I have some other variables to read from the current path and get some values.
$_path = $_SERVER['HTTP_HOST'] . request_uri();
preg_match('~id=(.*?)&~', $_path, $id);
$first = $id[1];
$second = substr($_path, -5);
where the first is the user id and the second is another variable that is unique per user.
My only problem is that I can't pass the $first and $second variables through the callback, and have them along with $reason $_reason = filter_xss($_values['reason']);
So, in my callback I want to be able to get the variables $first,$second with the $reason I already have. Now I have the $_path variables above my form, in the same function.
Then I want to perform an update query on MySQL, something like
UPDATE users SET reason=$reason
WHERE first=$first AND second=$second
where the column users has only the columns first,second and reason . Is this possible? Thanks in advance!
EDIT
I actually managed to do the first part and get the variables. I created two form inputs and I give them default values, the two variables I want to get, and I will hide them afterwards.
I still haven't figured out how to update MySQL though, so all answers are welcome!